通过Uid属性控制TextBlock组件的字体颜色

来源:互联网 发布:指南针软件诈骗 编辑:程序博客网 时间:2024/05/20 03:39
<Window x:Class="WpfApplication1.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:local="clr-namespace:WpfApplication1"       
       xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:cl="clr-namespace:System.Collections;assembly=mscorlib"
       Title="MainWindow" Height="250" Width="450">
    
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}" x:Key="textBlockTest">
            <Style.Triggers>
                <Trigger Property="Uid" Value="0">
                    <Setter Property="Foreground" Value="#EEEEEE" />
                </Trigger>
                <Trigger Property="Uid" Value="1">
                    <Setter Property="Foreground" Value="#000000" />
                </Trigger>
                <Trigger Property="Uid" Value="2">
                    <Setter Property="Foreground" Value="#FFFFFF" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
       <!-- <Button Style="{StaticResource highlightStyle}" Content="Hight Value" x:Name="btnVisible" Click="Button_Click" />-->
        <TextBlock Style="{StaticResource textBlockTest}" Text="TestTrigger" VerticalAlignment="Center" HorizontalAlignment="Center" Uid="1"/>
     </Grid>
</Window>
0 0
原创粉丝点击