是否有任何方法可以根据某些关于click事件的条件来停止Button命令的执行?
实际上,我想在我们的应用程序中单击某些按钮时弹出确认窗口。为了使其成为一个通用的解决方案,我做了以下工作:
AppBarButton
它已经包含一些依赖项属性。IsActionConfirmationRequired
和ConfirmationActionCommand
。如果IsActionConfirmationRequired
然后在左键单击事件中,我将打开确认弹出窗口。
有什么方法可以避免创建new ConfirmationActionCommand
和使用相同的Command
属性Button
吗?如果设置了Command
,我将遇到的问题是,Button
即使用户未确认仍然执行动作静止按钮命令,也要单击。
C#:
public class AppBarButton : Button
{
public AppBarButton()
{
this.Click += AppBarButton_Click;
}
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
if (button == null || IsActionConfirmationRequired == false || ConfirmationActionCommand == null)
return;
const string defaultMessage = "Do you really want to {0}";
string confirmationPopUpMessage = string.IsNullOrEmpty(ActionConfirmationMessage)
? DebugFormat.Format(defaultMessage, …
Run Code Online (Sandbox Code Playgroud)