Skip to content

Fixed delete dialog primary button focus issue #7882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/Files/Dialogs/FilesystemOperationDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
SecondaryButtonText="{x:Bind ViewModel.SecondaryButtonText, Mode=OneWay}"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">
<i:Interaction.Behaviors>
<!-- No need to specify CommandParameter - `e` is passed by default -->
<icore:EventTriggerBehavior EventName="Loaded">
<icore:InvokeCommandAction Command="{x:Bind ViewModel.LoadedCommand, Mode=OneWay}" />
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>

<ContentDialog.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -68,13 +62,14 @@
x:Load="{x:Bind ViewModel.PermanentlyDeleteLoad, Mode=OneWay}"
Content="Permanently delete"
IsChecked="{x:Bind ViewModel.PermanentlyDelete, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.PermanentlyDeleteEnabled, Mode=OneWay}" />
IsEnabled="False" />

<Grid>
<ListView
x:Name="DetailsGrid"
Grid.Row="1"
MaxHeight="200"
IsEnabled="False"
IsItemClickEnabled="False"
ItemsSource="{x:Bind ViewModel.Items}"
SelectionMode="{x:Bind ViewModel.ItemsSelectionMode, Mode=OneWay}">
Expand Down Expand Up @@ -213,9 +208,7 @@
x:Uid="ConflictingItemsDialogItemOptionReplaceExisting"
Command="{Binding ReplaceExistingCommand}"
Text="Replace" />
<MenuFlyoutItem
Command="{Binding SkipCommand}"
Text="{helpers:ResourceString Name=Skip}" />
<MenuFlyoutItem Command="{Binding SkipCommand}" Text="{helpers:ResourceString Name=Skip}" />
</MenuFlyout>
</muxc:SplitButton.Flyout>
</muxc:SplitButton>
Expand Down
19 changes: 19 additions & 0 deletions src/Files/Dialogs/FilesystemOperationDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Toolkit.Uwp.UI;
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
Expand All @@ -25,6 +26,24 @@ public FilesystemOperationDialog(FilesystemOperationDialogViewModel viewModel)

ViewModel = viewModel;
ViewModel.View = this;
ViewModel.LoadedCommand.Execute(null);
}

protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var primaryButton = this.FindDescendant("PrimaryButton") as Button;
if (primaryButton != null)
{
primaryButton.GotFocus += PrimaryButton_GotFocus;
}
}

private void PrimaryButton_GotFocus(object sender, RoutedEventArgs e)
{
(sender as Button).GotFocus -= PrimaryButton_GotFocus;
chkPermanentlyDelete.IsEnabled = ViewModel.PermanentlyDeleteEnabled;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a null check around line 45: "if (chkPermanentDelete != null)..".

DetailsGrid.IsEnabled = true;
}

private void MenuFlyoutItem_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
Expand Down