In a UWP
app I have used MenuFlyoutItem
to show drop down list. Here is xaml
code
<DropDownButton Style="{StaticResource DropDownButtonStyle1}" Name="MyDropDownButton"
Content="{Binding SelectedLanguage}"
RelativePanel.AlignRightWithPanel="True"
Margin="0,20,20,0"
FontSize="14">
<DropDownButton.Flyout>
<MenuFlyout x:Name="OptionMenu"
Placement="BottomEdgeAlignedRight">
</MenuFlyout>
</DropDownButton.Flyout>
</DropDownButton>
Programmatically i am adding MenuFlyoutItem
to MenuFlyout
foreach (Option option in _viewModel.Options)
{
MenuFlyoutItem item = new MenuFlyoutItem();
item.Text = option.text;
LanguagesMenu.Items.Add(item);
}
Problem: When user use app with keyboard interaction the first MenuFlyoutItem
is focused. I want different item to get focused (may be user previously selected item should get focused).
Example:
I have 3 option:
- Left
- Right
- Bottom
When user open MenuFlyout
by keyboard Enter
its by default focused first item -> Left
. I want 2nd item -> Right
to be focused.
How can i achieve this. I have read this Keyboard Interaction official doc but didn't find any idea.
You could directly use the Control.Focus(FocusState) Method to make the
MenuFlyoutItem
go to the focus state. I suggest you do this in the Flyout.Opened Event.Based on your code, I made a simple demo and you might check it.
Xaml:
Code behind:
Update:
Only make the item focused when the Enter key is pressed.