将Prism.Wpf更新至7.2版本
新增一个Class Library作为一个Mudule,在Module下添加Views文件夹,Views文件夹里添加UserControl ViewC,再添加一个类TestClass,如图:
TestClass 继承IModule接口:
public class TestClass : IModule { public void OnInitialized(IContainerProvider containerProvider) { var regionManager = containerProvider.Resolve<IRegionManager>(); regionManager.RegisterViewWithRegion("Test", typeof(ViewC)); } public void RegisterTypes(IContainerRegistry containerRegistry) { } }
主窗体加载Module:
App.xaml.cs
public partial class App : PrismApplication { protected override Window CreateShell() { return Container.Resolve<MainWindow>(); } protected override void RegisterTypes(IContainerRegistry containerRegistry) { } protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { moduleCatalog.AddModule<TestModule.TestClass>(); } }
MainWindow.xaml:
<ContentControl Grid.Column="2" prism:RegionManager.RegionName="Test" />