Prism&MEF构建开发框架 (一)
Shell框架XECA
shell.xaml主要起到是一个容器或壳的作用
<Window x:Class="XECA.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:inf="clr-namespace:MyGlobal.Infrustructure;assembly=MyGlobal.Infrustructure"
xmlns:prism="http://prismlibrary.com/"
xmlns:Controls="clr-namespace:MyGlobal.Infrustructure.Controls;assembly=MyGlobal.Infrustructure"
Title="工作平台" Height="300" Width="300" Background="{StaticResource myGraybrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Border Margin="5" Grid.Row="1" CornerRadius="5,5,5,5" BorderBrush="Black" BorderThickness="1">
<Grid Width="auto" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.15*"></ColumnDefinition>
<ColumnDefinition Width="0.85*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--<Controls:RoundedBox Margin="10" />-->
<Border Grid.Column="0" CornerRadius="10" Background="{StaticResource myGraybrush}" BorderBrush="#193441" BorderThickness="1" Margin="3" Padding="1">
<ItemsControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.MenuRegion }"/>
</Border>
<Border Grid.Column="1" CornerRadius="10" Background="#FCFFf5" BorderBrush="#193441" BorderThickness="0" Margin="1" Padding="0">
<Grid x:Name="ContentGrid" Grid.Row="1" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Border BorderThickness="1" Width="auto" Height="auto" CornerRadius="10,10,10,10" BorderBrush="Black" >
<Controls:AnimatedTabControl
x:Name="TabName"
SelectedIndex="0"
VerticalAlignment="Stretch"
ItemContainerStyle="{StaticResource ShellTabItemStyle}"
Background="{StaticResource headerBarBG}"
prism:RegionManager.RegionName="{x:Static inf:RegionNames.MCWrapRegion}"
AutomationProperties.AutomationId="TabId" />
</Border>
</Grid>
</Border>
</Grid>
</Border>
<StackPanel Orientation="Horizontal">
<Label HorizontalAlignment="Left" Margin="10,0,0,0" Width="Auto" Content="U-Project" FontWeight="Bold" Foreground="#fff" FontSize="24" FontFamily="Corbel"/>
</StackPanel>
</Grid>
</Window>
这里涉及两个关键技术点,一个是style的全局共享,另一个是采用AnimatedTabControl控件
App.config删除起始访问设置
<Application x:Class="XECA.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:XECA">
</Application>
Bootstrap.cs代码
using Prism.Unity;
using System.Windows;
using Microsoft.Practices.Unity;
using Prism.Modularity;
using XECA.Views;
using Prism.Mef;
using System.ComponentModel.Composition.Hosting;
using MyGlobal.Infrustructure.Behaviors;
using System;
using MyGlobal.Infrustructure;
using Prism.Logging;
using EntityFW;
using TestTabItems;
namespace XECA
{
[CLSCompliant(false)]
public partial class Bootstrapper : MefBootstrapper//采用MefBootstrapper
{
//程序运行日志管理
private readonly EnterpriseLibraryLoggerAdapter _logger = new EnterpriseLibraryLoggerAdapter();
protected override ILoggerFacade CreateLogger()
{
return _logger;
}
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(RICommands).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(EntityFWModule).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(TabTestModule).Assembly));
//业务模块采用目录catlog加载方式,即后续业务模块开发完成,将DLL扔到目录下即可
this.AggregateCatalog.Catalogs.Add(new DirectoryCatalog("../../Modules"));
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (Window)this.Shell;
Application.Current.MainWindow.Show();
}
protected override Prism.Regions.IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
{
var factory = base.ConfigureDefaultRegionBehaviors();
factory.AddIfMissing("AutoPopulateExportedViewsBehavior", typeof(AutoPopulateExportedViewsBehavior));
return factory;
}
protected override DependencyObject CreateShell()
{
DependencyObject x= this.Container.GetExportedValue<Shell>();
return x;
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗