Reputation: 9903
How can I set an element to be the default focus of other elements?
For example, say I have the following:
<StackPanel><Label/><Button/></StackPanel>
Clicking on any element will give it the focus if the Focusable is true.
However, what I need to say is "if the user clicks anywhere in the stackpanel, the button should get the focus". In other words, clicking on the label will give the focus to the button. This should work in small samples such as this one but also much larger ones with control templates.
Is this possible?
Upvotes: 0
Views: 691
Reputation: 2847
What about something like:
private void StackPanel_GotFocus(object sender, RoutedEventArgs e)
{
<elementName>.Focus();
}
Upvotes: 3