将值从一个视图模型传递到子视图模型 [英] Pass value from one viewmodel to sub viewmodel

查看:52
本文介绍了将值从一个视图模型传递到子视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.Net FW 4.5,VS 2013和SQLITE。我有一个包含标签项的MainWindow。每个选项卡项都有自己的视图,每个视图都有自己的VM。我在MainWindow上运行一个查询,将数据返回到数据网格。根据选择的SelectedItem,我需要查询将相关的子数据返回到包含我的view / viewmodel的选项卡...如何让我的主VM将值传递给我的子VM ...我我试过FindVisualParent,但它不起作用。我认为它在加载所有内容后加载我的值,因此不会在我的子VM查询中应用我的文件管理器...希望这是有道理的。



适用的最佳方法MVVM将不胜感激。

(将尝试上传示例项目...)


$ One在OneDrive上... 下载示例代码

I'm using .Net FW 4.5, VS 2013 and SQLITE. I've got a "MainWindow" that contains tab items. Each tab item has it's own view and each view has its own VM. I am running a query on my MainWindow that returns data to a datagrid. Depending on which "SelectedItem" is selected I need my query to return relevant sub data to my tab which contains my view/viewmodel... how do I get my main VM to pass a value to my Sub-VM... I've tried "FindVisualParent" but it does not work. I think it's loading up my value after everything is loaded and therefore not applying my filer on my sub-VM query... Hope this makes sense.

Best methods applicable to MVVM would be appreciated.
(will try and upload sample project...)

on OneDrive... Download Sample Code

推荐答案





您需要使用PRISM的事件聚合器模式将数据从一个VM传递到另一个VM。
Hi,

You need to use PRISM's event aggregator pattern to pass data from one VM to another VM.


这篇关于将值从一个视图模型传递到子视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆