小编Neh*_*eha的帖子

如何从其Click事件WPF停止执行按钮命令

是否有任何方法可以根据某些关于click事件的条件来停止Button命令的执行?

实际上,我想在我们的应用程序中单击某些按钮时弹出确认窗口。为了使其成为一个通用的解决方案,我做了以下工作:

  1. 我有WPF按钮类调用的扩展,AppBarButton它已经包含一些依赖项属性。
  2. 我还有2个其他属性,如下所示:IsActionConfirmationRequiredConfirmationActionCommand

如果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)

c# wpf command popup button

5
推荐指数
1
解决办法
3760
查看次数

标签 统计

button ×1

c# ×1

command ×1

popup ×1

wpf ×1