具有视图模型类型的 WPF Prism RegisterTypeForNavigation [英] WPF Prism RegisterTypeForNavigation with viewmodel type
本文介绍了具有视图模型类型的 WPF Prism RegisterTypeForNavigation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 WPF + Prism 中,如何使用视图模型类型导航到强类型对象:
In WPF + Prism, how can I navigate to a strongly type object using view-model type:
_navigationService.NavigateAsync<MainPageviewModel>();
为了让它起作用,我想我需要这样的东西:
For this to work I suppose I'd need something like this:
Container.RegisterTypeForNavigation<MainPage, MainPageViewModel>();
推荐答案
你只需要这个
Container.RegisterTypeForNavigation<MainPage>();
为了能够导航,您可能希望 viewmodellocator(在 xaml 上)为您创建视图模型.
to be able to navigate, then you probably want viewmodellocator (on the xaml) to create you the viewmodel.
这是你发送参数的方式
var navigationParameters = new NavigationParameters();
navigationParameters.Add("ParameterKey","TheParameter")
RegionManager.RequestNavigate("YouRegionName", new Uri(nameOf(MainPage), UriKind.Relative), navigationParameters);
当你收到它们时,你必须检查 OnNavigatedTo 方法中的 navigationContext 并通过密钥访问它们.
when you receive them, you have to check the navigationContext in OnNavigatedTo method and access them by the key.
这篇关于具有视图模型类型的 WPF Prism RegisterTypeForNavigation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文