惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
News and Events Feed by Topic
P
Privacy International News Feed
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
Security Latest
Security Latest
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 【当耐特】
博客园 - Franky
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
月光博客
月光博客
D
Docker
Webroot Blog
Webroot Blog
The GitHub Blog
The GitHub Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
S
Security Affairs
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
Lohrmann on Cybersecurity
T
Threatpost
量子位
S
Schneier on Security
V
Visual Studio Blog
S
Securelist
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
I
Intezer
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
小众软件
小众软件
罗磊的独立博客
雷峰网
雷峰网
Recorded Future
Recorded Future

博客园 - I'm CY

Graphviz(02) 汉字subgraph不显示汉字的处理 Graphviz(01) notepad++ Run xxx.gv How to design a product table for many kinds of product where each product has many parameters MVVM ICommand.CanExecute parameter is null Code First ef SQL Server 版本不支持数据类型“datetime2” 'System.ValueTuple, Version=0.0.0.0 required for Add-Migration on .NET 4.6.1 Class Library LDAP 相关链接 .NET WCF Return String 字符串有反斜杠的处理 word2010多级列表编号为什么会变成黑块 C# javascript 采用 RSA 加密解密 [LINK]List of .NET Dependency Injection Containers (IOC) 转:javascript判断IE浏览器 How to:Aborting a long running task in TPL How to: Cancel a Task and Its Children Exception has been thrown by the target of an invocation C#、IronPython、PowerShell 简单设计 大杀器 Linq手动添加EntitySet关系需要注意的地方
使用ContentPresenter,不使用ContentControl
I'm CY · 2018-12-18 · via 博客园 - I'm CY

参考: 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事件