My ChildWindow
has CloseButton and handler assigned to Click
event. Code (only for example):
Declaring close button:
<Button x:Name="CloseButton" Click="OnCloseButtonClick" />
Private counter (for diagnostics problem):
private uint _i;
Close event handler:
OnCloseButtonClick(object sender, RoutedEventArgs e)
{
DialogResult = true;
System.Diagnostics.Debug(_i++);
}
After fast clicking program can output "1", "2", "3", and so on...
As i know after setting DialogResult
= true
(or false
), ChildWindow should be closed and there should not be any way to raise the CloseButton's Click
event second time.
Can anyone help me to figure out cause of the problem and help to solve it without bool flags (executed/!executed)?
Copied from my comments
The problem is because the close activates the close window animation to close the window which means the button events are available until the animation finishes and the window is closed, see During Silverlight ChildWindow closing animation user can click any button
A quick and dirty solution is to add
((Button)sender).IsEnabled=false;
To the beginning of you click handler function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With