首页 > Windows开发 > 详细

WPF的DataTrigger使用

时间:2020-04-27 11:19:14      阅读:69      评论:0      收藏:0      [点我收藏+]

首先创建一个空的项目

技术分享图片

 

 

然后看看前台写的代码,如下图所示

技术分享图片

 

 

<Grid>
        <StackPanel HorizontalAlignment="Center"
                    VerticalAlignment="Center">
            <CheckBox Name="TestCheckBox"
                      Content="TestDataTriggerDemo"/>
            <TextBlock>
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property="Text" Value="Hello,这是测试!"/>
                        <Setter Property="FontSize" Value="36"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=TestCheckBox,Path=IsChecked}" Value="True">
                                <Setter Property="Text" Value="Hi,你好!数据触发器成功!"/>
                                <Setter Property="Foreground" Value="Blue"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </StackPanel>
    </Grid>

  我们来看看运行效果

技术分享图片

 

 原文作者:https://www.cnblogs.com/R00R/p/8100145.html

WPF的DataTrigger使用

原文:https://www.cnblogs.com/Smina/p/12784741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!