Change text color on mouse over in WPF using VB.NET

In this article, we will see how to change the text color on mouse over in WPF.
  • 5901
We will use 'SolidColorBrush' and 'Style' in  'Window.Resources' And ''Label use in 'Grid'. We will use SolidColorBrush as a Resource.

ControlTemplate:-We will use 'ControlTemplate' in the style. This 'ControlTemplate' change the color in your text.  We will use a 'ControlTemplate' to control the colors, and TextBlocks don't support ControlTemplates. The ControlTemplate change the foreground color of text when the user mouse over text.


<Window x:Class="Window1"
    Title="Window1" Height="300" Width="300">
        <SolidColorBrush x:Key="mouseOverColor"
                    Color="Pink" />
        <Style x:Key="myStyle" TargetType="Label">
            <Setter Property="Template">
                    <ControlTemplate TargetType="Label">
                            <Trigger Property="IsMouseOver"
                                <Setter Property="Foreground"
                       Value="{StaticResource mouseOverColor}" />
                        <ContentPresenter />
        <Label HorizontalAlignment="Center"
          Content="The Change Text Color"
          Style="{StaticResource myStyle}" />

Output:- After run the application show image this type.


After the mouse enter on the label and change the text color. The text color show in the pink color.



More Articles

© 2020 DotNetHeaven. All rights reserved.