diff --git a/WinUIGallery/ControlPages/FilePickerPage.xaml.cs b/WinUIGallery/ControlPages/FilePickerPage.xaml.cs index 3ad7b1ede..3cb6fa9f7 100644 --- a/WinUIGallery/ControlPages/FilePickerPage.xaml.cs +++ b/WinUIGallery/ControlPages/FilePickerPage.xaml.cs @@ -27,6 +27,10 @@ public FilePickerPage() private async void PickAFileButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickAFileOutputTextBlock.Text = ""; @@ -57,7 +61,7 @@ private async void PickAFileButton_Click(object sender, RoutedEventArgs e) Run run2 = new Run(); run2.FontWeight = Microsoft.UI.Text.FontWeights.Bold; run2.Text = file.Name; - + span.Inlines.Add(run1); span.Inlines.Add(run2); PickAFileOutputTextBlock.Inlines.Add(span); @@ -67,10 +71,17 @@ private async void PickAFileButton_Click(object sender, RoutedEventArgs e) PickAFileOutputTextBlock.Text = "Operation cancelled."; } + //re-enable the button + senderButton.IsEnabled = true; UIHelper.AnnounceActionForAccessibility(sender as Button, PickAFileOutputTextBlock.Text, "FilePickedNotificationId"); } + private async void PickAPhotoButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickAPhotoOutputTextBlock.Text = ""; @@ -114,11 +125,17 @@ private async void PickAPhotoButton_Click(object sender, RoutedEventArgs e) PickAPhotoOutputTextBlock.Text = "Operation cancelled."; } + //re-enable the button + senderButton.IsEnabled = true; UIHelper.AnnounceActionForAccessibility(sender as Button, PickAPhotoOutputTextBlock.Text, "PhotoPickedNotificationId"); } private async void PickFilesButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickFilesOutputTextBlock.Text = ""; @@ -164,11 +181,17 @@ private async void PickFilesButton_Click(object sender, RoutedEventArgs e) PickFilesOutputTextBlock.Text = "Operation cancelled."; } + //re-enable the button + senderButton.IsEnabled = true; UIHelper.AnnounceActionForAccessibility(sender as Button, PickFilesOutputTextBlock.Text, "FilesPickedNotificationId"); } private async void PickFolderButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickFolderOutputTextBlock.Text = ""; @@ -211,11 +234,17 @@ private async void PickFolderButton_Click(object sender, RoutedEventArgs e) PickFolderOutputTextBlock.Text = "Operation cancelled."; } + //re-enable the button + senderButton.IsEnabled = true; UIHelper.AnnounceActionForAccessibility(sender as Button, PickFolderOutputTextBlock.Text, "FolderPickedNotificationId"); } private async void SaveFileButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario SaveFileOutputTextBlock.Text = ""; @@ -239,7 +268,7 @@ private async void SaveFileButton_Click(object sender, RoutedEventArgs e) savePicker.SuggestedFileName = enteredFileName.Text; // Open the picker for the user to pick a file - StorageFile file= await savePicker.PickSaveFileAsync(); + StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync. @@ -256,7 +285,7 @@ private async void SaveFileButton_Click(object sender, RoutedEventArgs e) } // Another way to write a string to the file is to use this instead: // await FileIO.WriteTextAsync(file, "Example file contents."); - + // Let Windows know that we're finished changing the file so the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); @@ -278,6 +307,8 @@ private async void SaveFileButton_Click(object sender, RoutedEventArgs e) SaveFileOutputTextBlock.Text = "Operation cancelled."; } + //re-enable the button + senderButton.IsEnabled = true; UIHelper.AnnounceActionForAccessibility(sender as Button, SaveFileOutputTextBlock.Text, "FileSavedNotificationId"); } -} +} \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample1_cs.txt b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample1_cs.txt index 75e59083b..0b6a36aec 100644 --- a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample1_cs.txt +++ b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample1_cs.txt @@ -1,5 +1,9 @@ private async void PickAFileButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickAFileOutputTextBlock.Text = ""; @@ -29,4 +33,7 @@ { PickAFileOutputTextBlock.Text = "Operation cancelled."; } + + //re-enable the button + senderButton.IsEnabled = true; } diff --git a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample2_cs.txt b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample2_cs.txt index 1c8c892b3..e0cacb016 100644 --- a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample2_cs.txt +++ b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample2_cs.txt @@ -1,5 +1,9 @@ private async void PickAPhotoButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickAPhotoOutputTextBlock.Text = ""; @@ -32,4 +36,7 @@ { PickAPhotoOutputTextBlock.Text = "Operation cancelled."; } + + //re-enable the button + senderButton.IsEnabled = true; } \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample3_cs.txt b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample3_cs.txt index 470cd80a3..cf16a867f 100644 --- a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample3_cs.txt +++ b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample3_cs.txt @@ -1,5 +1,9 @@ private async void PickFilesButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickFilesOutputTextBlock.Text = ""; @@ -35,4 +39,7 @@ { PickFilesOutputTextBlock.Text = "Operation cancelled."; } + + //re-enable the button + senderButton.IsEnabled = true; } \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample4_cs.txt b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample4_cs.txt index d9604c627..14854db9d 100644 --- a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample4_cs.txt +++ b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample4_cs.txt @@ -1,5 +1,9 @@ private async void PickFolderButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario PickFolderOutputTextBlock.Text = ""; @@ -30,4 +34,7 @@ { PickFolderOutputTextBlock.Text = "Operation cancelled."; } + + //re-enable the button + senderButton.IsEnabled = true; } \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample5_cs.txt b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample5_cs.txt index 02b8c2bd4..f48d59f31 100644 --- a/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample5_cs.txt +++ b/WinUIGallery/ControlPagesSampleCode/System/FilePickerSample5_cs.txt @@ -1,5 +1,9 @@ private async void SaveFileButton_Click(object sender, RoutedEventArgs e) { + //disable the button to avoid double-clicking + var senderButton = sender as Button; + senderButton.IsEnabled = false; + // Clear previous returned file name, if it exists, between iterations of this scenario SaveFileOutputTextBlock.Text = ""; @@ -64,4 +68,7 @@ { SaveFileOutputTextBlock.Text = "Operation cancelled."; } + + //re-enable the button + senderButton.IsEnabled = true; } \ No newline at end of file