使用ContentPresenter,不使用ContentControl
参考: https://wpf.2000things.com/2017/04/06/1204-using-a-datatrigger-to-change-content-in-a-contentpresenter/
<Window.Resources>
<DataTemplate x:Key="DefaultContent">
<StackPanel>
<TextBlock Margin="10" Text="Some default content here.."/>
<TextBlock Margin="10" Text="Maybe show progress for operation"/>
</StackPanel>
</DataTemplate> <DataTemplate x:Key="AllDoneContent">
<StackPanel>
<TextBlock Margin="10" Text="** This is the ALL DONE content..."
Foreground="Green"/>
<TextBlock Margin="10" Text="Put anything you like here"/>
<Button Margin="10" Content="Click Me" HorizontalAlignment="Left"/>
</StackPanel>
</DataTemplate> <Style x:Key="MyContentStyle" TargetType="ContentPresenter">
<Setter Property="ContentTemplate" Value="{StaticResource DefaultContent}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding JobDone}" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource AllDoneContent}"/>
</DataTrigger>
</Style.Triggers>
</Style> </Window.Resources> <Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <ContentPresenter Grid.Row="0" Style="{StaticResource MyContentStyle}" Content="{Binding}"/> <Separator Grid.Row="1"/> <CheckBox Grid.Row="2" Margin="10" Content="Mark job done" IsChecked="{Binding JobDone}"/>
</Grid>
ContentControl通过DataTrigger进行切换模板时,原来绑定的模板会引发DataContext事件
使用ContentPresenter,不使用ContentControl的更多相关文章
- 重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容器控件: Border, Viewbox, Popup
原文:重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter ...
- ContentControl和ContentPresenter的应用
1:wpf中,所有的内容控件都继承自“ContentControl” ,所以我们可以直接应用“ContentControl”自定义我们“需要的”内容控件. 2:ContentControl具有Cont ...
- WPF的Presenter(ContentPresenter)(转)
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...
- 正确理解ContentPresenter
下图显示继承关系: ContentControl:Control (在Control類並沒有Content屬性, 所以在這之上再寫了一個ContentControl, 使控件有Content屬性可以顯 ...
- ContentPresenter
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...
- WPF:为什么使用ContentPresenter.ContentSource而不是Content属性?
因为ContentPresenter.ContentSource比Content属性加一个TemplateBinding看起来更方便?不仅仅是这些,实际上如果用ContentSource的话,Cont ...
- WPF的Presenter(ContentPresenter)
WPF的Presenter(ContentPresenter) 2010-12-20 14:34 by Clingingboy, 10619 阅读, 3 评论, 收藏, 编辑 这是2年前写了一篇文章 ...
- ContentPresenter理解
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...
- [转]WPF的Presenter(ContentPresenter)
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...
- WPF模板
WPF的中模板有三种:ControlTemplate.ItemsPanelTemplate.DataTemplate,他们继承抽象类FrameworkTemplate,下面是它们的继承关系: Wind ...
随机推荐
- DDoS攻防战 (四):CC攻击防御系统部署
1. 系统效果 此DDOS应用层防御系统已经部署在了http://www.yfdc.org网站上(如果访问失败,请直接访问位于国内的服务器http://121.42.45.55进行在线测试). 此防御 ...
- iOS开发基础控件--UILabel
UILabel 的常见属性和方法: //创建UIlabel对象 UILabel* label = [[UILabel alloc] initWithFrame:self.view.bounds]; / ...
- 在Windows10系统中配置和运行MongoDB数据库,linux开启mongdb
参考链接:http://jingyan.baidu.com/article/11c17a2c03081ef446e39d02.html linux中开启mongodb服务: 1. 进入到/data/ ...
- 认识Echarts(网址:http://echarts.baidu.com/tutorial.html#ECharts%20%E7%89%B9%E6%80%A7%E4%BB%8B%E7%BB%8D)
first.html: <!DOCTYPE html><html lang="en"><head> <meta charset=" ...
- MySQL数据库篇之多表查询
主要内容: 一.多表连接查询 二.复合条件连接查询 三.子查询 1️⃣ 多表连接查询 一.准备表 #建表 create table department( id int, name varchar( ...
- FreeSWITCH 使用SSL-WebSocket-WebRTC
阿里上买的域名, 申请了个免费ssl, 然后开始折腾,,,, 申请了ssl证书, 但是不提供 .pem 格式的下载(*/ω\*) 然后 把一堆 提供的 都下载下来了, 然后 又到网上 搜 crt/c ...
- 高性能Web服务器Nginx的配置与部署研究(5)Nginx配置符号
1. 容量符号 k 千字节 K 千字节 m 兆字节 M 兆字节 2. 时间符号 ms 毫秒 s 秒 m 分 h 时 d 日 w 周 M 月(按照30天计算) y 年(按照365天计算) 3. 示例 1 ...
- Git自动补全
一.简介 假使你使用命令行工具运行Git命令,那么每次手动输入各种命令是一件很令人厌烦的事情.为了解决这个问题,你可以启用Git的自动补全功能,完成这项工作仅需要几分钟. 二.操作步骤 1) cd ...
- Openssl ec命令
一.简介 椭圆曲线密钥处理工具 二.语法 openssl ec [-inform PEM|DER] [-outform PEM|DER] [-in filename] [-out filename] ...
- [SoapUI] SoapUI可以做到些什么?功能有多强大?
SoapUI. The Swiss-Army Knife of Testing. Whether you’re a tester, developer, business analyst, or ma ...