What's the best way to detect keyboard focus on a PropertyGrid item?
I've found TextBoxValueTemplateKey and DefaultValueTemplateKey, but I don't know whether I should really be replacing the existing template when I only need to listen for an event.
My specific scenario may help: I need to intercept keyboard input for my custom onscreen keyboard (not my decision). This is working for normal TextBoxes, but PropertyGridPropertyItems are giving me trouble.
I'm using attached properties, and they're getting me into this if statement, but none of my handlers ever get activated... (The first three sometimes miss the very first action on TextBoxes, although not in my very simple test application.)
var propGridItem = element as PropertyGridPropertyItem;
if (propGridItem != null)
{
propGridItem.AddHandler(FrameworkElement.MouseDownEvent, new MouseButtonEventHandler(FrameworkElement_MouseDown), true);
propGridItem.AddHandler(FrameworkElement.TouchDownEvent, new RoutedEventHandler(UIElement_Selected), true);
propGridItem.AddHandler(FrameworkElement.StylusDownEvent, new RoutedEventHandler(UIElement_Selected), true);
propGridItem.AddHandler(UIElement.GotFocusEvent, new RoutedEventHandler(UIElement_Selected), true);
}
That is, I never see program control in here:
private static void FrameworkElement_MouseDown(object sender, MouseButtonEventArgs e)
{
UIElement_Selected_impl(sender as UIElement);
}
private static void UIElement_Selected(object sender, RoutedEventArgs e)
{
UIElement_Selected_impl(sender as UIElement);
}
How should I be doing this?
[Modified 10 years ago]