确定从哪个视图/用户控件调用命令

发布于 2024-12-02 08:37:09 字数 149 浏览 0 评论 0原文

是否有任何明确的方法来确定从哪个视图(用户控件)调用命令?

例如,如果我有两个视图,每个视图都绑定到同一个 ViewModel,那么我如何确定从哪个视图调用特定命令?在这种情况下,为每个视图使用单独的命令不会产生任何影响,因为它是一个外部服务,应该通知特定的活动视图。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2024-12-09 08:37:09

我假设您从用户控件调用该命令。因此,如果您调用方法 someMethod,则要求该方法将 UserControl 对象作为参数。换句话说,你应该有类似的东西:

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

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

  }

并在你的用户 conrtoll 上调用该方法:

      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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文