Wednesday, February 16, 2011

Focus & WPF

Sometimes, I would like to take the focus off an element.

I don't necessarily want to put the focus on another element.

In an instance, where the element is within a "StackPanel", you can do:

// XAML
< stackpanel focusmanager.isfocusscope="True" name="MyStackPanel" > ...

// C#

FocusManager.SetFocusedElement(MyStackPanel, null);

This will not focus on any element, and as importantly, remove focus on any element that has focus in the StackPanel.

No comments:

Post a Comment