Silverlight命令动态绑定按钮? MVVM

发布于 2024-09-29 10:12:46 字数 284 浏览 2 评论 0原文

不确定我的设计是否正确(感谢指导!),但我有一个从很多地方调用的搜索视图。搜索屏幕有自己的 ViewModel。当用户从搜索屏幕中选择某些内容时(搜索后:),我需要将选择发送到请求进行搜索的任何视图(搜索屏幕是弹出窗口)。

我有一个视图定位器,当我向它发送消息时,它会弹出屏幕。该消息从 ViewModel (MVVM Light) 发送到视图定位器。

我要注册回电吗?广播消息?设置属性?将搜索屏幕上的“选择”按钮动态绑定回发起调用的视图模型?

嗯,问题太多,时间太少……

问候, 理查德

Not sure I'm designing this correctly (guidence is appreciated!), but I have a search view which is called from many places. Search screen has has it's own ViewModel. When a user selects something from the search screen (after searching :), I need to send the selection to whatever view requested the search to take place (search screen is a pop-up).

I have a view locator that pops up the screen screen when I send it a message. The message is sent from a ViewModel (MVVM Light) to the view locator.

Do I register a call back? Broadcast a message? Set a Property? Dynamically Bind the "Select" button on the search screen back to the view model that initiated the call?

mmmm so many questions, so little time...

Regards,
Richard

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

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

发布评论

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

评论(3

雨后彩虹 2024-10-06 10:12:46

我不确定 MVVM Light 是否有相当于 EventAggregator 的东西,但这是我能想到的最好的方式让你广播这个活动。

另一种选择是使用 反应式扩展 (Rx) 并制作接收者在打开搜索视图之前使用过滤器订阅事件,然后将过滤器传递给搜索视图,以便使用该过滤器调用实际操作,因此即使搜索视图模型请求搜索也是另一个视图模型将收到该事件。

I am not sure if MVVM Light has anything equivalent to an EventAggregator, but this is the best way I can think of for you to broadcast this event.

Another option would be to use the Reactive Extensions (Rx) and make the receiver subscribe to the event using a filter before you open the search view, then pass the filter to the search view so that the actual operation is called using that filter, so even when the search view model requested the search is the other view model that will receive the event.

鱼忆七猫命九 2024-10-06 10:12:46

我遇到了类似的问题,这就是我的做法。

我的弹出窗口有一个不同的 ViewModel,视图模型采用了您想要返回的对象的参数,例如您有 MainViewModel 和属性 Customer。在 PopupViewModel 构造函数中,我从 MainViewModel 传递了 Customer。当我进行搜索并找到您要查找的客户时,将该客户分配给 MainViewModel 中的客户引用。假设您已经实现了 INotifyPropertyChange 接口,一旦您选择了客户,它就会显示在您的主屏幕中。如果您理解,请告诉我,否则我会给您举一个例子。

希望这有帮助。

I had a similar issue and here is how I did it.

I had a difference ViewModel for my Pop Up window and the view model took a parameter of the object you want to return e.g. You have you MainViewModel and a property Customer. In the PopupViewModel constructor I passed the Customer from MainViewModel. When I did my search and found the Customer you are looking for, assign that customer to the Customer reference from MainViewModel. Assuming you have implemented INotifyPropertyChange interface, it will show up in your main screen as soon as you select a customer. Let me know if you understand or I will post you an example.

Hope this helps.

孤寂小茶 2024-10-06 10:12:46

我建议您将引用传递给界面元素,从而将调用转发到您的搜索。据我所知,所有这些都发生在视图模型层。

另一个选项是在搜索结果或搜索对象中设置一个标志,用于注册哪个接口进行了调用。我不确定在这种情况下你会如何进行回调。

I recommend that you pass the reference to the interface element making the call forward to your search. All of this is taking place at the view-model layer as far as I can tell.

The other option is to set a flag in the search result or search object that registers which interface made the call. I'm not sure how you would go about making a callback in this case.

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