简体   繁体   English

如果快速单击多次,ChildWindow关闭按钮事件处理程序将执行多次

[英]ChildWindow Close button event handler executes multiple times if it fast clicked many times

My ChildWindow has CloseButton and handler assigned to Click event. My ChildWindow将CloseButton和处理程序分配给Click事件。 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. 快速点击程序后可以输出“1”,“2”,“3”等等......正如我所知,在设置DialogResult = true (或false )之后,应该关闭ChildWindow并且不应该有任何方法来提高第二次关闭CloseButton的Click事件。

Can anyone help me to figure out cause of the problem and help to solve it without bool flags (executed/!executed)? 任何人都可以帮助我找出问题的原因并帮助解决它没有bool标志(执行/!执行)?

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 问题是因为关闭激活关闭窗口动画以关闭窗口,这意味着按钮事件可用,直到动画结束并且窗口关闭,请参阅Silverlight中的ChildWindow关闭动画用户可以单击任何按钮

A quick and dirty solution is to add 一个快速而肮脏的解决方案是添加

((Button)sender).IsEnabled=false;

To the beginning of you click handler function. 在您开始时单击处理函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM