WPF 棱镜从 shell 访问视图元素
我的应用程序中有一个带有一些按钮和选项卡以及一些模块的外壳。每个模块都有一个视图,其中包含一些元素,如数据网格、堆栈面板、文本框等。它们都有一个名称属性。现在,当我在 shell 上触发事件(例如单击按钮)时,我希望能够使用这些元素执行某些操作(例如清除用户在提供的文本框中写入的所有信息)。问题是,shell 看不到这些元素,也无法识别它们。有办法访问它们吗?
感谢您的任何建议。
I have a shell with some buttons and tabs and a few modules in my application. Each module has a view with some elements like datagrids, stackpanels, text boxes, etc. They all have a name attribute. Now when I fire an event on a shell (like click a button) I would like to be able to something with those elements (like clearing all the information written by the user in provided textboxes). The problem is, shell does not see those elements and cannot recognize them. Is there a way to access them?
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您采用类似于 Stocktrader 参考实现对 CompositeCommands 所做的方法。基本上,CompositeCommand 是包含其他 ICommand 集合的 ICommand 实现。在 RI 中,CompositeCommands 作为集中可用类的静态属性公开。
就您而言,您可以有一个复合的 ClearCommand。 shell 的视图模型会将其公开给 shell 视图,以便您可以将“清除”按钮连接到它。
然后,各个模块的视图模型将挂接到此 ClearCommand 中:
I'd suggest you take an approach like what the Stocktrader Reference Implementation does with CompositeCommands. Basically a CompositeCommand is an implementation of ICommand that contains a collection of other ICommands. In the RI, the CompositeCommands are exposed as static properties on a centrally available class.
In your case, you could have a composite ClearCommand. The viewmodel for the shell would expose this to the shell view so you could hook up, say, your Clear button to it.
The viewmodels for the various modules would then hook into this ClearCommand: