Override of OnGotFocus does not work
Posted: Tue Jan 17, 2017 10:35 pm
Hello Team,
I create a control custom control CMTextBox which inherits Textbox. And overrode the method 'OnGotFocus'.
But the GotFocus event is not triggered (OnGotFous is not called) when focus is moved to my CMTextBox.
Method 'OnLostFocus' also has the same problem.
However, overridden method OnPointerEntered works well.
Is this a bug of OnGotFocus and OnLostFocus?
If not, how to raises the GotFocus event and make method 'OnGotFocus' work.
Generic.xaml:
Override Method:
Regards,
XWang
I create a control custom control CMTextBox which inherits Textbox. And overrode the method 'OnGotFocus'.
But the GotFocus event is not triggered (OnGotFous is not called) when focus is moved to my CMTextBox.
Method 'OnLostFocus' also has the same problem.
However, overridden method OnPointerEntered works well.
Is this a bug of OnGotFocus and OnLostFocus?
If not, how to raises the GotFocus event and make method 'OnGotFocus' work.
Generic.xaml:
Code: Select all
<Style x:Key="CMTextBoxBaseStyle" TargetType="local:CMTextBoxBase">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CMTextBoxBase">
<TextBox>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="States">
<VisualState x:Name="Normal">
</VisualState>
<VisualState x:Name="PointerOver">
</VisualState>
<VisualState x:Name="Pressed">
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</TextBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Override Method:
Code: Select all
protected override void OnGotFocus(RoutedEventArgs eventArgs)
{
base.OnGotFocus(eventArgs);
}
protected override void OnPointerEntered(PointerRoutedEventArgs eventArgs)
{
base.OnPointerEntered(eventArgs);
}
Regards,
XWang