来自usercontrol的事件操作未传播到MainWindow以进行处理

时间:2015-08-03 09:16:48

标签: c# wpf events event-bubbling

我在datagrid中的用户控制按钮中附加了一个命令。 我在ViewModel中处理的这个命令

Private void EditClient(Client client)
{
     EditClientRequest(client.OID);
}

public event Action<int> EditClientRequest = delegate {   };

单击调试我可以看到调用了EditClient,参数确实是客户端的ID。但是在MainWindowViewModel中,这个事件永远不会被处理,它永远不会到来。

在MainWindowViewModel构造函数中我调用 ....

 _clientViewModel.EditClientRequest += NavToClient;

...

private void NatToClient(int clientId)
{
   _clientAddEditViewModel.myClientId = clientId;
   CurrentViewModel = _clientAddEditViewModel;
}

知道为什么会这样吗?

提前感谢您的帮助。

编辑:

MainWindowViewModel:

private ClientViewModel _clientViewModel = new ClientViewModel();
private ClientControlListViewModel _clientControlViewModel = new ClientControlListViewModel();
private BillListViewModel _billViewModel = new BillListViewModel();
private ClientAddEditViewModel _clientAddEditViewModel = new ClientAddEditViewModel();

public MainWindowViewModel()
    {
        _clientViewModel.EditClientRequest += NavToClient;
        CurrentViewModel = _clientViewModel;
    }

    private void NavToClient(int clientId)
    {
        _clientAddEditViewModel.myClientId = clientId;
        CurrentViewModel = _clientAddEditViewModel;

    }

0 个答案:

没有答案