簡體   English   中英

如何在模塊中使用棱鏡瀏覽多個視圖

[英]How to navigate using prism for multiple views in Module

我是Prism的新手,因此需要一些視圖之間導航的幫助。在我的項目中,我只有4個視圖,因此我在一個模塊中創建了所有視圖。 我已經創建了shell和bootstrapper。 我需要做的是,我需要將一些數據從一個視圖傳遞到另一個視圖(例如,第一個視圖具有雇員列表,我選擇一個雇員,然后單擊“按鈕”以獲取該雇員的詳細信息)。 目前,我正在使用ViewModel第一種方法`

_container.RegisterType<DashboardView>();
_container.RegisterType<PrepareRunView>();

_container.RegisterType<IDashboardViewViewModel, DashboardViewViewModel>();
_container.RegisterType<IPrepareRunViewViewModel, PrepareRunViewViewModel>();
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(DashboardView));
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(PrepareRunView));
  1. 在這種情況下,如何在視圖之間進行導航並傳遞數據?
  2. 我需要在Module類的Initialize函數中指定什么?

此外,在模塊類中,當我為同一區域注冊兩個視圖時,我能夠看到兩個視圖,因此我還需要激活和停用我的視圖。

提前致謝

第一個視圖的視圖模型(選擇雇員的視圖模型)需要引用Prism的IRegionManager對象。 您導航到第二個視圖,並按以下方式將一些數據傳遞給它,就像URL中的querystring值一樣:-

var uriQuery = new UriQuery();
uriQuery.Add("empid", "123");
// Add more name/value pairs if you wish!

var viewName = "your_view_name" + uriQuery;

_regionManager.RequestNavigate("your region name", viewName);

如您所見,您可以通過指定視圖名稱導航到視圖。 為此,您需要使用IoC容器在一個名稱下注冊視圖(操作方式取決於您使用的容器)。

在要導航到的視圖的視圖模型中,實現INavigationAware接口:

    public bool IsNavigationTarget(NavigationContext navigationContext)
    {
        return true;
    }

    public void OnNavigatedFrom(NavigationContext navigationContext)
    {
    }

    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        // This will be called whenever the view is navigated to.
        // Extract the querystring value(s).
        var employeeId = navigationContext.Parameters["empid"];
        .. etc..
    }

您可以使用事件聚合器進行通信

http://msdn.microsoft.com/en-us/library/ff921122.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM