开发者

WPF Prism Updating ViewModel

开发者 https://www.devze.com 2023-01-09 02:18 出处:网络
I am new to Prism WPF world, have one simple question. I have registered my view and viewmodel in the module initialise method like below

I am new to Prism WPF world, have one simple question.

I have registered my view and viewmodel in the module initialise method like below

        var navigatorView = new NavigationMenu.View.NavigationBarView();
        navigatorView.DataContext = m_Container.Resolve<NavigationMenuViewModel>();
        var regionManager = m_Contain开发者_运维百科er.Resolve<IRegionManager>();            
        regionManager.Regions[RegionNames.NavigationMenuRegion].Add(navigatorView);

Now if I want to modify my ViewModel then the only way i am able to do that is through ViewModel class only, is there any other way where I can update the viewmodel object registered with the unity container. Also i would like to know how can i get the object instance registered with the unity container.

Thanks and Regards, Harry


Any of your VMs or Modules should have that Initialize-Method, which gets those container, regionmanager and eventaggregator objects passed via parameters. In the first place (like your bootstrapper) you put them in those containers. You use a method like RegisterType for this. Then you can get those objects with the Resolve method, just like you did in your code example.

This means, wherever you want to manipulate a specific VM you use Resolve to get that VM. I probably didn't understand your question correctly. So please explain a little further, or be a bit more specific where you got problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消