ViewSortHint
ViewSortHintAttribute是为了指定哪个View先在Region中显示出来,设置为01的意思是当前排序优先级为01
[Export]
[ViewSortHint("01")]
public partial class AddInANavigationView : UserControl
RequestNavigate
//导航到MainRegion,把Uri指向的Page显示在PrismRegionShell里命名为MainRegion的Region里
namespace EmptyDemoModule
{
//ViewSortHintAttribute是为了指定哪个View先在Region中显示出来,设置为02的意思是当前排序优先级为02
[ViewSortHint("02")]
public partial class EmptyNavigationItem : UserControl
{
IRegionManager _regionManager;
ILoggerFacade logger;
public EmptyNavigationItem(IRegionManager regionManager,ILoggerFacade logger)
{
logger.Log("初始化【空示例】按钮", Category.Info, Priority.Low); //显示Log信息
InitializeComponent();
this._regionManager = regionManager;
this.logger = logger;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri(ViewNames.EmptyPage, UriKind.Relative);
//导航到MainRegion,把Uri指向的Page显示在PrismRegionShell里命名为MainRegion的Region里
_regionManager.RequestNavigate(RegionNames.MainRegion, uri);
//显示Log信息
logger.Log("导航到Empty示例", Category.Info, Priority.Low);
}
}
}
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export("REModuleB")]
//[PartCreationPolicy(CreationPolicy.NonShared)]
/// <summary>
/// REModuleB.xaml 的交互逻辑
/// </summary>
public partial class REModuleB : UserControl
{
public REModuleB()
{
InitializeComponent();
//this.DataContext = new PGModuleB();
}
}
using Infrastrature;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ModuleB
{
[Export("PGModuleB")]
/// <summary>
/// PGModuleB.xaml 的交互逻辑
/// </summary>
public partial class PGModuleB : Page
{
private static Uri ContactMainWindowViewUri = new Uri("ContactMainWindowView", UriKind.Relative);
private static Uri REModuleBUri = new Uri("REModuleB", UriKind.Relative);
[Import]
public IRegionManager regionManager;
public PGModuleB()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.regionManager.RequestNavigate(RegionNames.CenterRegion, ContactMainWindowViewUri, CheckForError);
//REModuleB B = new REModuleB();
//NavigationService ns = NavigationService.GetNavigationService(this);
//ns.Content = B;
}
void CheckForError(NavigationResult nr)
{
if (nr.Result == false)
{
throw new Exception(nr.Error.Message);
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.regionManager.RequestNavigate(RegionNames.RightRegion, REModuleBUri, CheckForError);
}
}
}
Prism的导航(Navigation)通常是用Uri在页面之间传值,用RequestNavigate进行页面跳转并传递参数,例如:
以下是代码片段: 1: //Dedicate region 2: IRegion mainRegion = ...; 3: mainRegion.RequestNavigate(new Uri("InboxView?key=123&par=456", UriKind.Relative)); 4: 5: //Use RegionManager 6: IRegionManager regionManager = ...; 7: regionManager.RequestNavigate("MainRegion", new Uri("InboxView?key=123&par=456", UriKind.Relative)); 8: regionManager.RequestNavigate(RegionNames.TabRegion, "EmployeeDetails", NavigationCompleted); |