Wpf,Unity6
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Prism" version="5.0.0" targetFramework="net452" />
<package id="Prism.Composition" version="5.0.0" targetFramework="net452" />
<package id="Prism.Interactivity" version="5.0.0" targetFramework="net452" />
<package id="Prism.Mvvm" version="1.0.0" targetFramework="net452" />
<package id="Prism.PubSubEvents" version="1.0.0" targetFramework="net452" />
<package id="CommonServiceLocator" version="1.2" targetFramework="net452" />
<package id="Prism.UnityExtensions" version="5.0.1" targetFramework="net452" />
<package id="Unity" version="3.5.1404.0" targetFramework="net452" />
</packages>
using Microsoft.Practices.Prism.UnityExtensions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Microsoft.Practices.Prism.Modularity; using MA; using MB; namespace WpfApplication6 { public class WpfBootstrapper:UnityBootstrapper { protected override DependencyObject CreateShell() { return Container.TryResolve<Shell>(); } protected override void ConfigureModuleCatalog() { base.ConfigureModuleCatalog(); ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog; moduleCatalog.AddModule(typeof(ModuleA)); moduleCatalog.AddModule(typeof(ModuleB)); } protected override IModuleCatalog CreateModuleCatalog() { return base.CreateModuleCatalog(); } protected override void InitializeShell() { base.InitializeShell(); App.Current.MainWindow = (Window)this.Shell; App.Current.MainWindow.Show(); } } }
using Microsoft.Practices.Prism.Modularity; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; using MA.Views; using MA.ViewModel; namespace MA { public class ModuleA : IModule { private readonly IRegionManager _regionManager; private readonly IUnityContainer _container; public ModuleA(IUnityContainer container,IRegionManager regionManager) { _container = container; _regionManager = regionManager; } public void Initialize() { _container.RegisterType<IGetStudentList, StudentVM>(new ContainerControlledLifetimeManager()); this._regionManager.RegisterViewWithRegion("MARegion",typeof(MAView)); } } }
<UserControl x:Class="MA.Views.MAView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:MA.Views" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="300"> <Grid Background="Red"> <DataGrid x:Name="dg" ItemsSource="{Binding StuList}" AutoGenerateColumns="True" BorderBrush="Yellow" BorderThickness="5"> </DataGrid> </Grid> </UserControl>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现