功能区ICommand的访问控制

时间:2012-02-02 07:00:51

标签: c# wpf icommand

我是WPF新手,并已开始在VS2010中使用Ribbon控件。

 public class RibbonAddCustomer : ICommand
  {
    public void Execute(object parameter)
    {
        AddCustomer addCustomer = new AddCustomer();
        addCustomer.ShowDialog();
        Customer myCustomer = addCustomer.customerDetails;
        addCustomer.Close();

        // MainWindow.Customers.Add(myCustomer);

    }

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public event EventHandler CanExecuteChanged;
}

我创建了一个WPF RibbonWindow并在表单中添加了一个功能区。我附加了一个显示CustomerDetails表单的事件处理程序。现在我想将输入的客户添加到主窗体上的ComboBox中。事件触发,客户从显示中输入。我无法弄清楚如何从RibbonAddCustomer事件访问窗体上的控件来更新主窗体上的ComboBox。

我尝试将参数传递给RibbonAddCustomer事件,但这始终为null。

 <r:RibbonButton Command = "{StaticResource mycmd}" CommandParameter="{Binding}" Label="Add Customer" />

有什么建议吗?有点迷茫。 -Thanks。

1 个答案:

答案 0 :(得分:0)

您可以在RibbonControl中创建一个Window属性,以便引用主窗口。

public MainWindow MyMainWindow {get;set;}

当您的应用程序启动时,将MyMainWindow属性设置为主窗口。