基于Prism 7.1

最近工作中可能会用到TabControl所以作为小菜的我提前预习了一下,结果并没有我想的那么简单,于是乎 各种网上查,本来用wpf的人就不多 prism 的可查的资料就更少的可怜了,于是我 从prism的官方例子中 找到了合适的,为了防止自己忘记了,先写记录在这里。

首先我就直接用界面区域 注册 吧tabcontrol 直接写上去了,然后写了个UserControl 用prism 的导航框架直接去导结果就成了这个样子

发现Tabitem的Header没有,于是就开始查 Header怎么弄出来,功夫不负有心人,终于让我在官方的例子中找到了。

官方的例子是这样弄的,做一个tabitem的样式,在tabitem 的vm层加一个用来显示header内容的属性,绑定好就可以了,结果就是下面的样子

这样tabitem 的 header 就显示出来了,知道原理之后我们就可以定制各种好看的tabitem的样式了,下面是代码,写的匆忙请见谅

前端住窗口

 <Window.Resources><Style TargetType="{x:Type TabItem}"><Setter Property="Header" Value="{Binding DataContext.Title}"></Setter></Style></Window.Resources><Grid><Grid.RowDefinitions><RowDefinition Height="40"></RowDefinition><RowDefinition Height="*"></RowDefinition></Grid.RowDefinitions><Grid Grid.Row="0"></Grid><Grid Grid.Row="1"><Grid.ColumnDefinitions><ColumnDefinition Width="*"></ColumnDefinition><ColumnDefinition Width="3*"></ColumnDefinition></Grid.ColumnDefinitions><StackPanel Grid.Column="0"><Button Height="30" Margin="3" Command="{Binding NavigateCommand}" CommandParameter="FirstPage">FirstPage</Button><Button Height="30" Margin="3" Command="{Binding NavigateCommand}" CommandParameter="SecondPage">SecondPage</Button><Button Height="30" Margin="3" Command="{Binding NavigateCommand}" CommandParameter="ThirdPage">ThirdPage</Button></StackPanel><TabControl Grid.Column="1" prism:RegionManager.RegionName="TabRegion"></TabControl></Grid></Grid>

主窗口后端代码

public partial class MainWindow : Window{private IRegionManager _regionManager;public ICommand NavigateCommand { get; set; }public MainWindow(IRegionManager regionManager){InitializeComponent();_regionManager = regionManager;this.DataContext = this;NavigateCommand = new DelegateCommand<string>(SetFirst);}private void SetFirst(string path){if(path != null)_regionManager.RequestNavigate("TabRegion", path);  }}

App.xaml.cs

 public partial class App : PrismApplication{protected override void RegisterTypes(IContainerRegistry containerRegistry){containerRegistry.RegisterForNavigation<FirstPage>();containerRegistry.RegisterForNavigation<SecondPage>();containerRegistry.RegisterForNavigation<ThirdPage>();}protected override Window CreateShell(){return Container.Resolve<MainWindow>();}}

tabitem 用户控件后端代码

public partial class FirstPage : UserControl{public string Title { get; set; }public FirstPage(){InitializeComponent();Title = "FIRST PAGE";this.DataContext = this;}}

View Code

完整代码:链接: https://pan.baidu.com/s/1cDZ2yCZoaHCM_GgP4qfTtQ 提取码: 6hsb

最后,抱大佬大腿

转载于:https://www.cnblogs.com/wuyaxiansheng/p/10654263.html

Prism 的 TabControl 导航相关推荐

  1. Prism源代码解析(IRegionManager)

    概要 本文主要介绍Prism的IRegionManager, 主要分析源代码的执行流程, 来介绍内部实现的几个核心接口调用过程. 通过本文, 你可以熟练的掌握Prism当中以下接口的作用以及使用方法, ...

  2. Prism Dialog

    1.注册Dialog对应信息 protected override void RegisterTypes(IContainerRegistry containerRegistry){container ...

  3. 0613-prism-docs

    https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ff648465(v%3dpandp.10) 依赖注入 使用Prism Libra ...

  4. [Prism]Composite Application Guidance for WPF(10)——系列目录导航

    [Prism]Composite Application Guidance for WPF(10)--系列目录导航                                            ...

  5. Prism区域异常问题分析(导航失效?)

    前文 本篇文章主要讨论在WPF当中使用Prism区域导航的失效的问题, 在其它的博客当中也出现了多次讨论这个问题以及对应的解决方法, 例如重写OnInitialized方法等等.我认为这都不是解决问题 ...

  6. 在 WPF 中使用 Prism DryIOC 加载应用程序时导航到默认视图

    通过重写CreateShell方法: CreateShell方法:/// <inheritdoc /> protected override Window CreateShell() {v ...

  7. Prism框架研究(一)

    从今天起开始写一个Prism框架的学习博客,今天是第一篇,所以从最基本的一些概念开始学习这个基于MVVM的框架的学习,首先看一下Prism代表什么,这里引用一下比较官方的英文解释来看一下:Prism ...

  8. Prism框架(一)——概述Prism框架的设计目的是用来帮助构建丰富、灵活、易维护的WPF和Si...

    Si Prism框架(一)--概述Prism框架的设计目的是用来帮助构建丰富.灵活.易维护的WPF和Si 提问者:mfksnr120(ID:187460) | 悬赏 0.0 希赛币 | 回答数:0 | ...

  9. prism在java_Prism 框架应用-基础知识篇

    Prism 框架概念 prism was the code name for the guidance formally known as the Composite Application Guid ...

最新文章

  1. 利用欧拉角旋转正交_张量旋转=矩阵旋转?
  2. glide源码中包含了那种设计模式_推荐一个好用的拍照选图库,致敬Glide
  3. 为何类型转型Integer[] = Object[]可以,而Integer[] = int[]却不行
  4. 【转】JS跨域(ajax跨域、iframe跨域)解决方法及原理详解(jsonp)
  5. [BZOJ3992]序列统计
  6. 在TextView中实时显示数据
  7. c语言 调用父类方法,关于C++:如何从派生类函数调用父类函数?
  8. 1081. Rational Sum (20)-PAT甲级真题
  9. 怎么多快好省地学习中文自然语言处理
  10. Word如何快速绘制你需要的作文稿纸
  11. FFT蝶形算法的verilog实现专题——从FFT算法的定义开始入手
  12. SpringMVC---- SpringMVC返回JSON数据
  13. 使用CSS打造很有亲和力的各种web2.0操作提示效果 使用CSS打造很有亲和力的各种web2.0操作提示效果
  14. 黑暗城堡(最短路径树)
  15. 泰国80亿互联网记录数据库泄漏,疑遭黑客攻击
  16. 从js给html的form表单赋值,js获取form表单数据和form表单赋值
  17. 下载网盘资源如何更快呢?
  18. Linux之文件共享
  19. Markdown For Typora
  20. 怎么在C语言软件上验证程序,一种验证指针程序的方法

热门文章

  1. 第2节 storm实时看板案例:10、redis的安装使用回顾
  2. SQL 数据库的自动备份(Procedures实现)
  3. Go语言基础练习题系列2
  4. C#方法参数传递机制
  5. 【翻译】在Sencha Touch中创建离线/在线代理
  6. 乘法器之四( 乘加器(Sum of multiplication))
  7. .NET : 在单元测试中使用外部文件作为数据源
  8. (13)ISE14.7bit文件生成mcs文件(FPGA不积跬步101)
  9. (42)FPGA状态机二段式
  10. FPGA时钟资源使用