You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a ContentDialog is shown which contains interactive controls, the display of the focus highlight is inconsistent:
If the dialog is opened via a button click, the highlight is not shown. The first interactive control on the dialog is focussed, but the highlight is not shown.
If the dialog is opened via a KeyUp event handler or in response to a KeyboardAccelerator invocation, the focus highlight is shown.
Steps to reproduce the bug
Create a new project in Visual Studio. Choose "Blank App, Packaged (WinUI 3 in Desktop)" as the project template.
Name the project "CheckboxTest".
Replace the MainWindow.xaml file contents with the XAML below:
<Windowx:Class="CheckboxTest.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:CheckboxTest"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"Title="ContentDialog Focus Test">
<StackPanelOrientation="Horizontal"HorizontalAlignment="Center"VerticalAlignment="Center">
<ButtonName="ShowDialogButton"Content="Show Dialog"Click="ShowDialogButton_Click" />
<ContentDialogx:Name="DeleteConfirmationDialog"Title="Delete file"PrimaryButtonText="Move to Recycle Bin"CloseButtonText="Cancel"DefaultButton="Close">
<StackPanelVerticalAlignment="Stretch"HorizontalAlignment="Stretch"Spacing="12">
<TextBlockTextWrapping="Wrap"Text="Are you sure you want to move file 'somefile.jpg' to the Recycle Bin?" />
<CheckBoxx:Name="DeleteDontAskCheckbox"Content="Don't ask me again" />
</StackPanel>
</ContentDialog>
</StackPanel>
</Window>
Replace the MainWindow.xaml.cs file code with:
usingSystem;usingSystem.Threading.Tasks;usingMicrosoft.UI.Xaml;usingMicrosoft.UI.Xaml.Controls;usingMicrosoft.UI.Xaml.Input;namespaceCheckboxTest;publicsealedpartialclassMainWindow:Window{publicMainWindow(){this.InitializeComponent();this.Content.KeyUp+=Content_KeyUp;}privateasyncvoidContent_KeyUp(objectsender,KeyRoutedEventArgse){if(e.Key==Windows.System.VirtualKey.Delete){if(awaitOpenDeleteDialog()==ContentDialogResult.Primary){// ... do delete stuff}}}privateasyncvoidShowDialogButton_Click(objectsender,RoutedEventArgse){if(awaitOpenDeleteDialog()==ContentDialogResult.Primary){// ... do delete stuff}}privateasyncTask<ContentDialogResult>OpenDeleteDialog(){DeleteConfirmationDialog.XamlRoot=Content.XamlRoot;returnawaitDeleteConfirmationDialog.ShowAsync();}}
Run the project and click the "Show Dialog" button. Observe that the dialog is shown with no focus highlight present on the checkbox control:
Close the dialog by pressing Enter or selecting the "Cancel" button.
Press Delete. Observe that the dialog is shown with the first interactive element highlighted as the focussed control:
Expected behavior
The display of the focus highlight should be consistent, i.e. independent of the method used to show the ContentDialog. I suggest not showing the highlight until the user uses Tab to move the focus around the dialog's controls.
Describe the bug
When a ContentDialog is shown which contains interactive controls, the display of the focus highlight is inconsistent:
KeyUp
event handler or in response to aKeyboardAccelerator
invocation, the focus highlight is shown.Steps to reproduce the bug
Create a new project in Visual Studio. Choose "Blank App, Packaged (WinUI 3 in Desktop)" as the project template.
Name the project "CheckboxTest".
Replace the
MainWindow.xaml
file contents with the XAML below:MainWindow.xaml.cs
file code with:Close the dialog by pressing Enter or selecting the "Cancel" button.
Press Delete. Observe that the dialog is shown with the first interactive element highlighted as the focussed control:
Expected behavior
The display of the focus highlight should be consistent, i.e. independent of the method used to show the ContentDialog. I suggest not showing the highlight until the user uses Tab to move the focus around the dialog's controls.
Screenshots
No response
NuGet package version
None
Windows version
Windows 11 (24H2): Build 26100
Additional context
Additional context may be found on my StackOverflow question here: https://stackoverflow.com/questions/79376328/winui-3-how-to-set-focus-to-a-contentdialog-button/79382988
The text was updated successfully, but these errors were encountered: