Prism 的 TabControl 导航
基于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;
}
}
完整代码:链接: https://pan.baidu.com/s/1cDZ2yCZoaHCM_GgP4qfTtQ 提取码: 6hsb
最后,抱大佬大腿
Prism 的 TabControl 导航的更多相关文章
- Prism 4 文档 ---第8章 导航
作为同用户具有丰富的交互的客户端应用程序,它的用户界面(UI)将会持续不断的更新来反映用户工作的当前的任务和数据.用户界面可以进行一段时间相当大的变化作为用户交互的应用程序中完成各种任务.通过 ...
- 7. 组合你的UI
1. UI布局关键概念 一个组合应用UI的根节点被称作Shell,一般只有一个Shell.Shell作为应用的主页,包含一个或者多个域.域是内容占位符,可以包含一个或者多个View.有很多控件可以作为 ...
- WPF如何实现一款类似360安全卫士界面的程序?(共享源码!)
以前学习Windows Form编程的时候,总感觉自己做的界面很丑,看到360安全卫士.迅雷等软件的UI设计都非常美观,心里总是憧憬着要是自己能实现这样的UI效果该多好!!!另一个困扰我的问题是,这个 ...
- [Xamarin]我的Xamarin填坑之旅(二)
上一篇交代了我Xamarin填坑的背景,大概聊了聊第一步环境配置,第二步创建项目和开发框架选择.如果有一个可用的梯子,这部分基本不会出错. 接下来就具体聊一聊写代码的过程中遇到的一些事儿. 第三步是码 ...
- 从PRISM开始学WPF(八)导航Navigation-更新至Prism7.1
原文:从PRISM开始学WPF(八)导航Navigation-更新至Prism7.1 0x6Navigation [7.1updated] Navigation 在wpf中并没有变化 Basic Na ...
- 从PRISM开始学WPF(八)导航Navigation?
原文:从PRISM开始学WPF(八)导航Navigation? 0x6Navigation Basic Navigation Prism中的Navigation提供了一种类似导航的功能,他可以根据用户 ...
- Prism for WPF 搭建一个简单的模块化开发框架(六)隐藏菜单、导航
原文:Prism for WPF 搭建一个简单的模块化开发框架(六)隐藏菜单.导航 这个实际上是在聊天之前做的,一起写了,也不分先后了 看一下效果图,上面是模块主导航,左侧是模块内菜单,现在加一下隐藏 ...
- 8. Prism导航
1. 背景 导航是为了实现不同界面的切换,是一种组织系统功能的方式.提供两种导航,一是基于View切换,二是基于ViewModel状态. 2. 基于View切换的导航 最常用导航方式.在该种导航中首先 ...
- Xamarin.Forms + Prism,整理页面导航跳转流程
3个Page,Page1 -> Page2 -> Page3 -> Page2 -> Page1. PageViewModel实现接口:INavigatingAware, IN ...
随机推荐
- php在线支付流程
1.企业与银行的两种接入方式: (1).企业直接与银行对接. 优点:直接与银行进行财务结算,资金安全,适合资金流较大企业. 缺点:开发和维护工作量较大,分别与每家银行签订合同,每年需交 ...
- 让php支持多线程,win下安装pthreads
1.检查PHP版本是否支持线程安全 在phpinfo()的显示页中,搜索Thread Safety,如果是enabled,则PHP版本是线程安全的. 2.在http://windows.php.net ...
- git format-patch 用法【转】
本文转载自:http://blog.csdn.net/xzongyuan/article/details/9425739 git format-patch相对于git diff更便于操作,是更新的打包 ...
- PAT 1052 卖个萌 (20)(代码+思路)
1052 卖个萌 (20)(20 分) 萌萌哒表情符号通常由"手"."眼"."口"三个主要部分组成.简单起见,我们假设一个表情符号是按下列格 ...
- Codeforces 689B. Mike and Shortcuts SPFA/搜索
B. Mike and Shortcuts time limit per test: 3 seconds memory limit per test: 256 megabytes input: sta ...
- spring 注解 注入属性 和 注解完成bean定义
1. 使用 @Autowired 和 @Resource 注解来注入属性 2. 使用 @Component.@Repository.@Service.@Controller 注解,就将该类定义为一个B ...
- easyjweb ejs 2014.2.25
一 .简单 easyjweb 项目 1. 创建一个web 项目 , 将easyjweb-corejar 包 和required 包下的所有jar 包拷到项目下. 2.写一个 action .. pa ...
- 8.14 右键自定义菜单 更加iframe 内容高度调整 iframe高度 js定时
<div class="main_contain" id="z_div" style="position: relative;"> ...
- 用Notepad++在文本文件里快速在每行头尾都加上指定的内容(转载)
- js实现a_b变成A B的两种方法
1.var key = 'a_b'; var a = key.replace(/\b.|_./g, function (i) { if (i.length === 2) { i = ' ' + i[1 ...