简体   繁体   English

具有多个UserControl(和ViewModel)的页面

[英]Page with multiple UserControls (and ViewModels)

So, i have several pages with several UserControls on each. 因此,我有几个页面,每个页面上都有多个UserControls。 One of the UCs presents on every page, and is taking info from DataService (which is used as info storage) in its constructor. 每个页面上都有一个UC,并且正在其构造函数中从DataService(用作信息存储)中获取信息。

While switching between pages, UC's ViewModel constructor is not called, so it is not updating info from DataService. 在页面之间切换时,不会调用UC的ViewModel构造函数,因此它不会从DataService更新信息。 It is called once, during creation of very first page. 在创建第一页的过程中调用一次。

Any ideas? 有任何想法吗? Should i just make a method, and call it from codebehind? 我应该只创建一个方法,然后从代码隐藏中调用它吗? Or can i somehow bind viewmodel's fields to DataService? 或者我可以以某种方式将viewmodel的字段绑定到DataService?

Ok, answer is pretty simple. 好的,答案很简单。 Just need to pass new parameter while solving SimpleIoc. 解决SimpleIoc时只需传递新参数即可。

SimpleIoc.Default.GetInstance<MainViewModel>((uidHolder++).ToString());

Reference (some info about mvvm-light's ioc) : how to use MVVMLight SimpleIoc? 参考(有关mvvm-light的ioc的一些信息): 如何使用MVVMLight SimpleIoc?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM