forum

Home / DeveloperSection / Forums / Change OnClick label color WPF

Change OnClick label color WPF

Anonymous User730415-Dec-2013

Im coming from a C# winforms background and I would normally do all this in code. I have several Labels that I'm using as a menu. When the mouse hovers over them the text changes color by:

<Page.Resources>

    <SolidColorBrush x:Key="normalColor" Color="White" />

    <SolidColorBrush x:Key="mouseOverColor" Color="Gold" />

    <Style TargetType="Label" x:Key="menuItemStyle">

        <Style.Triggers>

            <Trigger Property="IsMouseOver" Value="False">

                <Setter Property="Foreground" Value="{StaticResource normalColor}"/>

            </Trigger>

            <Trigger Property="IsMouseOver" Value="True">

                <Setter Property="Foreground" Value="{StaticResource mouseOverColor}"/>

            </Trigger>

        </Style.Triggers>

    </Style>

</Page.Resources>

      <Label x:Name="Label_Video1" Style="{StaticResource menuItemStyle}" Content="1.Video 1."  FontSize="16" HorizontalAlignment="Left" Margin="25,74,0,0" VerticalAlignment="Top" MouseLeftButtonDown="Label_Video1_MouseLeftButtonDown" />

    <Label x:Name="Label_Video2" Style="{StaticResource menuItemStyle}" Content="2. Video 2." FontSize="16" HorizontalAlignment="Left" Margin="25,105,0,0" VerticalAlignment="Top" MouseDown="Label_Video2_MouseDown"/>

When the user clicks a label I want it to stay a certin color (In this case Gold) and all the others to stay their normal colour. So if a label has been previously clicked and I click another label it will go from gold to white etc


wpf wpf 
Updated on 16-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By