【问题标题】:Command Binding not working in pop-up window命令绑定在弹出窗口中不起作用
【发布时间】:2018-09-25 09:41:19
【问题描述】:

我正在使用命令绑定,它在类似的其他窗口中工作,但不是一个。我检查了 DataContext 并发现它是正确的。事件 EventHandler CanExecuteChanged 实际上永远不会受到打击。 Codebehind 设置为 XAML 的 DataContext

XAML

<Button CommandParameter="Flow" Content="Test" 
        Command="{Binding SetAutoYAxisCommand, Mode=OneWay}" />

代码背后

public RelayCommand ExportHistoricalCommand { get; set; }
public RelayCommand1 SetAutoYAxisCommand { get; set; }

public TransientPipeDialog(TransientPipeModel transientPipeModel)
{
    InitializeComponent();

    this.ParentModel = transientPipeModel;
    this.TransientPipeModel = transientPipeModel.DeepCopy();
    ExportHistoricalCommand = new RelayCommand(ExportHistoricalData);
    SetAutoYAxisCommand = new RelayCommand1(SetAutoYAxis, o => true);
}

【问题讨论】:

  • 我假设你的按钮在

标签: wpf xaml


【解决方案1】:

尝试在弹出窗口打开时初始化您的命令:

private void Popup_Opened(object sender, System.EventArgs e)
{
    SetAutoYAxisCommand = new RelayCommand1(SetAutoYAxis, o => true);
}   

<Popup Opened="Popup_Opened">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2019-11-13
    • 2012-08-22
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多