15

I have a textblock that currently has a trigger that sets the foreground colour when the mouse enters and back to the default when it leaves. The problem I have is that I would also like the mouse pointer to change I currently have the following

    <Style TargetType="TextBlock" x:Key="FlatStyleButton">
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Background" Value="#FF333333" />
        <Style.Triggers>
            <EventTrigger RoutedEvent="UIElement.MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="CornflowerBlue" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="UIElement.MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="White" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Style.Triggers>
    </Style>

I have tried adding <Setter Property="Cursor" Value="Hand"></Setter> to various places but it never seems to work

John
  • 1,403
  • 3
  • 19
  • 31
  • 2
    there is a trigger to do this at http://stackoverflow.com/questions/1132971/wpf-trigger-to-change-cursor –  May 16 '13 at 10:33
  • this may also help you http://www.infragistics.com/community/forums/t/62255.aspx –  May 16 '13 at 10:34
  • I already tried something like those and it didnt work – John May 16 '13 at 10:36

1 Answers1

34

Sorry guys Proper school boy error on my part im afraid, what I was trying would have worked but I was modifiying in the wrong resource file. So if anyone else is intrested the answer was:

<Style TargetType="TextBlock" x:Key="FlatStyleButton">
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Background" Value="#FF333333" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Cursor" Value="Hand" />
            </Trigger>
            <EventTrigger RoutedEvent="UIElement.MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="CornflowerBlue" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="UIElement.MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Foreground.Color" To="White" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Style.Triggers>
    </Style>
John
  • 1,403
  • 3
  • 19
  • 31