参考: 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的更多相关文章

  1. 重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容器控件: Border, Viewbox, Popup

    原文:重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter ...

  2. ContentControl和ContentPresenter的应用

    1:wpf中,所有的内容控件都继承自“ContentControl” ,所以我们可以直接应用“ContentControl”自定义我们“需要的”内容控件. 2:ContentControl具有Cont ...

  3. WPF的Presenter(ContentPresenter)(转)

    这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...

  4. 正确理解ContentPresenter

    下图显示继承关系: ContentControl:Control (在Control類並沒有Content屬性, 所以在這之上再寫了一個ContentControl, 使控件有Content屬性可以顯 ...

  5. ContentPresenter

    这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...

  6. WPF:为什么使用ContentPresenter.ContentSource而不是Content属性?

    因为ContentPresenter.ContentSource比Content属性加一个TemplateBinding看起来更方便?不仅仅是这些,实际上如果用ContentSource的话,Cont ...

  7. WPF的Presenter(ContentPresenter)

    WPF的Presenter(ContentPresenter) 2010-12-20 14:34 by Clingingboy, 10619 阅读, 3 评论, 收藏, 编辑 这是2年前写了一篇文章 ...

  8. ContentPresenter理解

    这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...

  9. [转]WPF的Presenter(ContentPresenter)

    这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...

  10. WPF模板

    WPF的中模板有三种:ControlTemplate.ItemsPanelTemplate.DataTemplate,他们继承抽象类FrameworkTemplate,下面是它们的继承关系: Wind ...

随机推荐

  1. promtheus 配置文件

    全局配置 global 属于全局的默认配置,它主要包含 4 个属性, scrape_interval: 拉取 targets 的默认时间间隔. scrape_timeout: 拉取一个 target ...

  2. java算法 第七届 蓝桥杯B组(题+答案) 9.取球博弈

    9.取球博弈  (程序设计) 两个人玩取球的游戏.一共有N个球,每人轮流取球,每次可取集合{n1,n2,n3}中的任何一个数目.如果无法继续取球,则游戏结束.此时,持有奇数个球的一方获胜.如果两人都是 ...

  3. 使用jquery修改表单的提交地址

    基本思路: 通过使用jquery选择器得到对应表单的jquery对象,然后使用attr方法修改对应的action 示例程序一: 默认情况下,该表单会提交到page_one.html 点击button之 ...

  4. c# ftp 上传文件 与 下载文件

    接着上一篇说. 上一篇说了根据配置文件获取路径,并判断路径在服务器中是否存在.如果不存在则在服务器中建立一个. 然后就是往路径下面传输文件了.. 代码: //连接ftp private void Co ...

  5. Opencv threshold

    图像的二值化就是将图像上的像素点的灰度值设置为0或255,这样将使整个图像呈现出明显的黑白效果.在数字图像处理中,二值图像占有非常重要的地位,图像的二值化使图像中数据量大为减少,从而能凸显出目标的轮廓 ...

  6. 区分 hdfs hbase hive hbase适用场景

    区分 hdfs hbase hive hbase适用场景 收藏 八戒_o 发表于 11个月前 阅读 308 收藏 1 点赞 0 评论 0 摘要: hdfs hbase hive hbase适用场景 H ...

  7. Nginx概述、安装及配置详解

    nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...

  8. Openssl errstr命令

    一.简介 errstr命令用于查询错误代码 二.语法 errstr [-stats] <errno> 选项 -stats:打印哈希表状态 errno:错误号 三.实例 1.查看错误信息 : ...

  9. [Training Video - 4] [Groovy] Constructors in groovy, this keyword

    Bank.log = log Bank b1 = new Bank() b1.name = "BOA" b1.minbalance = 100 b1.city="Lond ...

  10. [SoapUI] 通过Groovy写文本文件

    如果文件已经存在,先删除,然后向文件中追加失败信息 if(maxRecordFail>0){ def testResultFile = new File(projectDir+"\\T ...