当鼠标悬停时,TextBlock文本用不同颜色加下划线

问题描述 投票:-1回答:1

当鼠标悬停在文本上时,我想使用与字体颜色不同的颜色为Textblock文本着色。

除了创建自定义控件之外,该怎么做?

<TextBlock Text="5000.00" FontSize="20" >
            <!--<TextBlock.TextDecorations>
                <TextDecoration Location="Underline">
                    <TextDecoration.Pen>
                        <Pen Brush="Green"></Pen>
                    </TextDecoration.Pen>
                </TextDecoration>
            </TextBlock.TextDecorations>-->
       <TextBlock.Style>
            <Style TargetType="TextBlock">
                <Style.Triggers>
                    <Trigger Property ="IsMouseOver" Value="True">
                        <Setter Property= "Foreground" Value="Black"/>
                        <Setter Property="TextDecorations" Value="Underline" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
c# wpf textblock underline
1个回答
0
投票
<TextBlock Text="5000.00" FontSize="20" >
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Style.Triggers>
                <Trigger Property ="IsMouseOver" Value="True">
                    <Setter Property="TextDecorations">
                        <Setter.Value>
                            <TextDecorationCollection>
                                <TextDecoration Location="Underline">
                                    <TextDecoration.Pen>
                                        <Pen Brush="Red"/>
                                    </TextDecoration.Pen>
                                </TextDecoration>
                            </TextDecorationCollection>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <Trigger Property ="IsMouseOver" Value="False">
                    <Setter Property="TextDecorations">
                        <Setter.Value>
                            <TextDecorationCollection>
                                <TextDecoration Location="Underline">
                                    <TextDecoration.Pen>
                                        <Pen Brush="LimeGreen"/>
                                    </TextDecoration.Pen>
                                </TextDecoration>
                            </TextDecorationCollection>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>
© www.soinside.com 2019 - 2024. All rights reserved.