wpf的动态Tab的例子,使用Prism
引用Prism.Core,Prism.Wpf 和 Prism.Unity
修改App.xaml 的类型替换为 PrismApplication
修改App.xaml.cs:
/// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : PrismApplication { protected override Window CreateShell() { return Container.Resolve<MainWindow>(); } protected override void InitializeShell(Window shell) { if (Container.Resolve<LoginWindow>().ShowDialog() == false) { Application.Current?.Shutdown(); } else if (Container.Resolve<MainWindow>().ShowDialog() == false) { Application.Current?.Shutdown(); } else base.InitializeShell(shell); } /// <summary> /// ioc注入 /// </summary> /// <param name="containerRegistry"></param> protected override void RegisterTypes(IContainerRegistry containerRegistry) { //containerRegistry.Register<>(); } /// <summary> /// 模板配置, /// </summary> /// <param name="moduleCatalog"></param> protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { //可以改成自动扫描 moduleCatalog.AddModule<MenuModule>(); moduleCatalog.AddModule<BaseInfoModule>(); //base.ConfigureModuleCatalog(moduleCatalog); } }
运行效果
源码地址:https://gitee.com/null_044_9298/prismWpfDemo.git