问题
I am developing a rich user interface using Silverlight 5. I have lots of ChildWindows. Child Window has sort of buttons which are bound with Commands. I realized that if Child Window Close method is called, closing animation begins. However during animation user can click any button, which causes unexpected situations. To prevent this I need to unbind all buttons immediately on close request. I don't like to put this logic everywhere. Do you have any better solutions?
<Grid x:Name="LayoutRoot" DataContext="{StaticResource ResourceKey=viewModel}">
<StackPanel>
<TextBlock Text="{Binding ConfirmMessage}" HorizontalAlignment="Center" Margin="5"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Width="120" Height="30" Content="Yes" Margin="5" Command="{Binding ConfirmedCommand}"/>
<Button Width="120" Height="30" Content="No" Margin="5" Command="{Binding RejectedCommand}"/>
</StackPanel>
</StackPanel>
</Grid>
To clarify, use a simple child window with above content. And bind ConfirmedCommand and RejectedCommand to simple commands which executes informative message boxes. Try close child window with close button on top right. During animation fastly click one of the buttons. You will see the message.
Edit: I have removed closing animation and it solved the problem in another way. For those who wants animation original problem remains same.
来源:https://stackoverflow.com/questions/12588642/during-silverlight-childwindow-closing-animation-user-can-click-any-button