0

我希望当鼠标悬停在按钮/文本块上时文本块的前景会发生变化。我已经尝试过了,但这不起作用:

<DataTemplate>
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding Header}"/>
        <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
                Margin="5,-3,0, 0" 
                Visibility="{Binding IsCloseButtonVisible}"
                Command="{Binding CloseSelectedTabCommand}">
            <Button.Content>
                <TextBlock Text="x" Foreground="LightGray">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Foreground" Value="Red"/>
                                </Trigger>
                             </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                </TextBlock>
            </Button.Content>
        </Button>
    </StackPanel>
</DataTemplate>
4

1 回答 1

2

您需要在样式中而不是在 TextBlock 中设置前景才能使其工作。

<TextBlock Text="HelloWorld ">
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="LightGray"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="Red"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>
于 2013-11-06T00:59:15.067 回答