13

我有一个文本块,它当前有一个触发器,当鼠标进入时设置前景色,离开时设置回默认值。我遇到的问题是我也想改变鼠标指针我目前有以下

    <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>

我曾尝试添加<Setter Property="Cursor" Value="Hand"></Setter>到各个地方,但它似乎从来没有工作

4

1 回答 1

33

对不起,伙计们,我担心正确的男生错误,我正在尝试的东西会起作用,但我正在修改错误的资源文件。因此,如果其他人感兴趣,答案是:

<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>
于 2013-05-16T10:39:32.743 回答