开发者

Determining from which View/UserControl a Command was called

Is there any definitive way of determining from which View (UserControl) a command was called?

For instance, if I have two Views, each tied to the same ViewModel, how might I determine from which View a particular command was called? Having a separate command for each View开发者_运维百科 would not make a difference in this scenario, as it is an external service which ought to be notified of the particular active View.


I am assuming that you call the command from a usercontrol. So if you call the method someMethod for example then require that method to take a UserControl object as a parameter. In other words you should have somethin like:

  Public void someMethod(UserControl u, other params...){

    If( u is SomeUsercontrol){
      \\do somethin
      } else if....

  }

And on your user conrtoll call that method as:

      someMethod(this, .....) \\ the this keyword will send a UserControl object if you call that method within a UserControl class. In other words it will pass itself as a parameter
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜