I was trying to implement a dialog box with layout as something like this
I wanted keyboard behavior as
- Control at radio button 'a' OR 'b' OR 'c' -> Tab press -> Cancel button -> Tab press -> Save button -> Tab press -> Last selected radio button among 'a' OR 'b' or 'c' (even first radio button 'a' will do).
- Arrow key navigation between 'a', 'b' and 'c' radio buttons.
A very easy way is to use <RadioButtons>
to group individual <Radiobutton>
but that is not affordable with the overall project as using the dependency library winui 2+ is messing up with other parts of the code and affecting functionality of some feature.
After researching on internet and reading through this documentation, I tried <ListView>
which was causing two issues
- Pressing spacebar button no longer selects any option.
- Narrator always says "Selected" for each radio button even if the radio button is not selected.
Upon further search, I landed upon this .
Code:
<ContentDialog>
<StackPanel>
<StackPanel XYFocusKeyboardNavigation="Enabled" TabFocusNavigation="Once">
<RadioButton Content="a" XYFocusKeyboardNavigation="Enabled" />
<RadioButton Content="b" XYFocusKeyboardNavigation="Enabled" />
<RadioButton Content="c" XYFocusKeyboardNavigation="Enabled" />
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Uid="Cancel" Name="CancelButton" Click="Cancel" Margin="5" IsEnabled="False"/>
<Button x:Uid="Save" Name="SaveButton" Click="Save" Margin="5" IsEnabled="False"/>
</StackPanel>
</StackPanel>
</ContentDialog>
Upon implementation, most of the issues with narrator and navigation were gone, except for 1 issue:
The control never lands on 'b' radio button.
Being on 'a' radio button, pressing down arrow key doesn't works. Pressing up arrow key moves the control to 'c'.
Being on 'c' radio button, pressing up arrow key doesn't works. Pressing down arrow key moves the control to 'a'.
I even tried XYFocusDownNavigationStrategy="Projection"
on 'c' radio button and XYFocusUpNavigationStrategy="Projection"
on 'a' radio button, but it didn't work.
How to fix this issue?