0
votes

If I have a group of buttons as a wpf control, for example:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
    <Button Content="Button 1"/>
    <Button Content="Button 2"/>
</StackPanel>
</UserControl>

and run this application, Button 1, as expected, has focus on start-up, but with no FocusVisualStyle, i.e., dotted line surrounding the button. Pressing the tab key gives Button 2 focus, and gives it FocusVisualStyle. Pressing tab again gives focus back to Button 1 with FocusVisualStyle.

Here's the behaviour I'm after: On start-up, Button 1 should have focus with no FocusVisualStyle. Pressing tab keeps focus on Button 1 and gives it FocusVisualStyle (not Button 2). Pressing tab again cycles through the buttons giving each focus and FocusVisualStyle accordingly.

Ideally I want to achieve this in XAML, but not sure it is possible having tried various combinations of setting the focused element via the focus manager. Any suggestion how this might be achieved?

1
I think that pressing tab to focus something that is already focused is a bad behaviour. I would rather suggest you to use style triggers for this purpose. - Guerudo

1 Answers

0
votes

Its hacky way but should do the trick for you if you dont have any Default buttons in that page. Just set

IsDefault="True" 

for the first button. If this interferes with any other control behaviors in your screen then you have to write a behavior in XAML for adding removing IsDefault on tabs.