使用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 ...
随机推荐
- Java Servlet调用数据库复习
首先要导入jar包. 剩下的基本就是模版式的代码了: public class main { // JDBC 驱动名及数据库 URL static final String JDBC_DRIVER = ...
- Spring Boot实践——三种拦截器的创建
引用:https://blog.csdn.net/hongxingxiaonan/article/details/48090075 Spring中的拦截器 在web开发中,拦截器是经常用到的功能.它可 ...
- Form表单标签的Enctype属性的作用及应用示例介绍
Enctype :指定将数据回发到服务器时浏览器使用的编码类型.用于表单里有图片上传. 编码类型有以下三种: application/x-www-form-urlencoded: 在发送前编码所有字符 ...
- 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 15—Anomaly Detection异常检测
Lecture 15 Anomaly Detection 异常检测 15.1 异常检测问题的动机 Problem Motivation 异常检测(Anomaly detection)问题是机器学习算法 ...
- Think In Java 读后感
近期拜读了Think in Java 一书,这里是一些读后感. 此书不仅仅是市面上那种教会你怎么用系统API来编程的书,那种书太多. 此书不仅仅从头开始讲述了如何 ...
- 使用CocoaPods卡在了"pod setup"界面的解决办法
http://blog.csdn.net/samoy/article/details/51956799 有时候,我们在执行pod install或pod search命令时,会在终端偶现卡在’ ...
- c# 遍历一个对象里面的全部属性
比如我现在有一个Student的对象,里面有属性stuName,stuAge,stuGender,我现在该怎么写循环才能遍历这几个属性? Student s=new...... foreach (Sy ...
- ssh的发展历程与基本原理
一.ssh是什么 SSH(Secure Shell)是一个提供数据通信安全.远程登录.远程指令执行等功能的安全网络协议,最初提出目的是替代非安全的Telnet.rsh.rexec等远程Shell协议. ...
- Linux静态库与动态库详解
引言 为了代码的复用性和模块化,我们常常使用一些库文件,在Windows操作系统下位.lib .dll作为静态库和动态库的后缀名. 在Linux下,静态链接库名字一般为libabcdef.a,其中ab ...
- EZOJ #257
传送门 分析 先进行缩点 之后从终点倒着跑 对于一组边如果有一个点不能到达则这组边直接废掉 最后看只用没废掉的边能不能从起点走到终点 代码 #include<iostream> #incl ...