Updating the foreground of a label on window active property-WPF

Posted by Deb on Stack Overflow See other posts from Stack Overflow or by Deb
Published on 2010-06-09T06:52:28Z Indexed on 2010/06/09 9:52 UTC
Read the original article Hit count: 166

Filed under:

I have a label which shows the name of the window. I want to update the colour of the label on the IsActive property of the window using styles and triggers so that all the labels inheriting this style should exhibit the same property. Please can anyone suggest me how?

I tried like this:

<Style TargetType="{x:Type Label}" x:Key="HeaderLabel">
    <Style.Triggers>
        <DataTrigger Binding="{Binding (Window.IsActive)}" Value="True">
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="FontFamily" Value="Arial"/>
            <Setter Property="Foreground" Value="Black"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding (Window.IsActive)}" Value="False">
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="FontFamily" Value="Arial"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
        </DataTrigger>

    </Style.Triggers>
</Style>

© Stack Overflow or respective owner

Related posts about wpf