WPF 棱镜从 shell 访问视图元素

发布于 2024-09-07 15:14:21 字数 206 浏览 3 评论 0原文

我的应用程序中有一个带有一些按钮和选项卡以及一些模块的外壳。每个模块都有一个视图,其中包含一些元素,如数据网格、堆栈面板、文本框等。它们都有一个名称属性。现在,当我在 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 技术交流群。

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

发布评论

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

评论(1

神妖 2024-09-14 15:14:21

我建议您采用类似于 Stocktrader 参考实现对 CompositeCommands 所做的方法。基本上,CompositeCommand 是包含其他 ICommand 集合的 ICommand 实现。在 RI 中,CompositeCommands 作为集中可用类的静态属性公开。

就您而言,您可以有一个复合的 ClearCommand。 shell 的视图模型会将其公开给 shell 视图,以便您可以将“清除”按钮连接到它。

然后,各个模块的视图模型将挂接到此 ClearCommand 中:

GlobalCommands.ClearCommand.RegisterCommand(new DelegateCommand(x => ClearAllFields()));

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:

GlobalCommands.ClearCommand.RegisterCommand(new DelegateCommand(x => ClearAllFields()));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文