5

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)?

Dzmitry Martavoi
  • 6,867
  • 6
  • 38
  • 59
  • 1
    I take it adding the first line `((Button)sender).IsEnabled=false` is not a solution? – Bob Vale Nov 19 '12 at 11:46
  • Yes, it is.But it looks like workaround. And i also want to know cause of the problem. – Dzmitry Martavoi Nov 19 '12 at 11:48
  • I think there is no problem. A button can be clicked mutiple times and its up to you to disable the button, when you do not want it to be clickable – Jehof Nov 19 '12 at 11:51
  • 3
    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 [SO] (http://stackoverflow.com/questions/12588642/during-silverlight-childwindow-closing-animation-user-can-click-any-button) – Bob Vale Nov 19 '12 at 11:56
  • Thanks, that`s what i`m looking for. – Dzmitry Martavoi Nov 19 '12 at 12:03

1 Answers1

2

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.

Community
  • 1
  • 1
Bob Vale
  • 18,094
  • 1
  • 42
  • 49
  • mixing event handler logic with UI visual state looks annoying for me :) but, as i understood there is now way good way to solve it. – Dzmitry Martavoi Nov 19 '12 at 12:11