How to determine what caused GotFocus event of WPF TextBox - mouse click or TAB key? I need to change border color if focus was set with TAB key and leave border's standart color if focus was set with mouse click. So I need to extract from event args what caused an event, or (better) write trigger to put it into TextBox style.
views:
116answers:
2
A:
I would suggest using the OnKeyUp and OnMouseUp events rather than the GotFocus event to determine this. In OnKeyUp, you will need to test (see Eventargs) that it was the Tab key that was pressed.
AJ
2010-06-22 11:26:32
A:
Could you extend the WPF TextBox and then use that for all your text boxes instead? Then you could have some overridden events to determine how you were focused, or to do the border changes.
class MySpecialTextBox : TextBox
{
protected override void OnIsKeyboardFocusWithinChanged(System.Windows.DependencyPropertyChangedEventArgs e)
{
// Focused by keyboard
}
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
{
// Focused by mouse
}
protected override void OnIsMouseCaptureWithinChanged(System.Windows.DependencyPropertyChangedEventArgs e)
{
// Focused by mouse
}
}
Cory Larson
2010-06-22 11:56:36
Yes I can, but for me it is better to use style triggers, because I want to make it a part of a style. Is it possible? The thing is, I want to create a copy of ExpressionLight style that would be more like real style of expression light than one that is in WPFToolkit.
Boyd_Rice
2010-06-24 23:56:06