Skip to content
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

Fix: Prevent FilePicker button double-click #1580

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions WinUIGallery/ControlPages/FilePickerPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down Expand Up @@ -67,10 +71,16 @@ 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 = "";

Expand Down Expand Up @@ -114,11 +124,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 = "";

Expand Down Expand Up @@ -164,11 +180,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 = "";

Expand Down Expand Up @@ -211,11 +233,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 = "";

Expand Down Expand Up @@ -278,6 +306,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");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "";

Expand Down Expand Up @@ -29,4 +33,7 @@
{
PickAFileOutputTextBlock.Text = "Operation cancelled.";
}

//re-enable the button
senderButton.IsEnabled = true;
}
Original file line number Diff line number Diff line change
@@ -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 = "";

Expand Down Expand Up @@ -32,4 +36,7 @@
{
PickAPhotoOutputTextBlock.Text = "Operation cancelled.";
}

//re-enable the button
senderButton.IsEnabled = true;
}
Original file line number Diff line number Diff line change
@@ -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 = "";

Expand Down Expand Up @@ -35,4 +39,7 @@
{
PickFilesOutputTextBlock.Text = "Operation cancelled.";
}

//re-enable the button
senderButton.IsEnabled = true;
}
Original file line number Diff line number Diff line change
@@ -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 = "";

Expand Down Expand Up @@ -30,4 +34,7 @@
{
PickFolderOutputTextBlock.Text = "Operation cancelled.";
}

//re-enable the button
senderButton.IsEnabled = true;
}
Original file line number Diff line number Diff line change
@@ -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 = "";

Expand Down Expand Up @@ -64,4 +68,7 @@
{
SaveFileOutputTextBlock.Text = "Operation cancelled.";
}

//re-enable the button
senderButton.IsEnabled = true;
}