当前位置: 首页 > news >正文

WPF的Prism框架的使用

安装Prism.DryIoc库:

Prism的区域和模块化:

一个区域可以显示一个用户控件

一个模块就是一个项目,也就是一个类库

动态切换用户控件的案例:

<Grid><Grid.RowDefinitions><RowDefinition Height="auto"/><RowDefinition/></Grid.RowDefinitions><StackPanel Orientation="Horizontal"><Button Margin="5" Content="打开模块A" Command="{Binding OpenCommand}" CommandParameter="ViewA"/><Button Margin="5" Content="打开模块B" Command="{Binding OpenCommand}" CommandParameter="ViewB"/><Button Margin="5" Content="打开模块C" Command="{Binding OpenCommand}" CommandParameter="ViewC"/></StackPanel><ContentControl prism:RegionManager.RegionName="ContentRegion" Grid.Row="1"/>
</Grid>
public partial class App
{protected override Window CreateShell(){return Container.Resolve<MainView>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){// 依赖注入containerRegistry.RegisterForNavigation<ViewA>();containerRegistry.RegisterForNavigation<ViewB>();containerRegistry.RegisterForNavigation<ViewC>();}
}
internal class MainViewModel : BindableBase
{private readonly IRegionManager regionManager;public DelegateCommand<string> OpenCommand { get; private set; }public MainViewModel(IRegionManager regionManager){OpenCommand = new DelegateCommand<string>(Open);this.regionManager = regionManager;}private void Open(string obj){regionManager.Regions["ContentRegion"].RequestNavigate(obj);}
}

多模块的情况下动态切换一个区域的用户控件:

大部分的代码是和上面一样的

模块A中的ModuleAProfile文件:

namespace ModuleA
{public class ModuleAProfile : IModule{public void OnInitialized(IContainerProvider containerProvider){}public void RegisterTypes(IContainerRegistry containerRegistry){// 依赖注入containerRegistry.RegisterForNavigation<ViewA>();}}
}

主项目中的App.xaml:

public partial class App
{protected override Window CreateShell(){return Container.Resolve<MainView>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){}protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog){moduleCatalog.AddModule<ModuleAProfile>();moduleCatalog.AddModule<ModuleBProfile>();base.ConfigureModuleCatalog(moduleCatalog);}
}

http://www.lryc.cn/news/537869.html

相关文章:

  • LeetCode每日精进:142.环形链表II
  • CPP集群聊天服务器开发实践(五):nginx负载均衡配置
  • easyexcel解析excel文件的时候报错
  • Android设备 网络安全检测
  • word分栏使得最后一页内容自动平衡
  • 完全免费稳定WebTerm网页版在线SSH连接,在线远程连接云服务器,可以控制背景,支持SFTP访问服务器文件。无需安装即可在线连接和管理服务器的SSH终端工具。支持跨平台设备。
  • 微信小程序医院挂号系统
  • 编程题-最大子数组和(中等-重点【贪心、动态规划、分治思想的应用】)
  • 阿里云视频点播,基于thinkphp8上传视频
  • 《探秘AI绿色计算:降低人工智能硬件能耗的热点技术》
  • 神经网络常见激活函数 9-CELU函数
  • 软考高级《系统架构设计师》知识点(四)
  • opencv交叉编译
  • 安装vite报错Install for [ ‘create-vite@latest‘ ] failed with code 1
  • Spring框架中都用到了哪些设计模式?
  • LabVIEW 中 dotnet.llb 库功能
  • C# 变量,字段和属性的区别
  • wordpress模板文件结构超详解
  • android studio下载安装汉化-Flutter安装
  • 数据开放共享和平台整合优化取得实质性突破的智慧物流开源了
  • 如何设置 Nginx 连接超时并进行测试(Nginx优化)
  • springboot整合mybatis-plus(保姆教学) 及搭建项目
  • 知识管理成功:关键指标和策略,研究信息的投资回报率
  • 【算法】链表
  • 集成测试总结文档
  • 关于Dest1ny:我的创作纪念日
  • Python爬虫-猫眼电影的影院数据
  • 【计算机网络】传输层数据段格式
  • nsc account 及user管理
  • 晶闸管主要参数分析与损耗计算