如何在角半径的文本块中正确修复悬停?

时间:2018-06-06 22:36:51

标签: wpf xaml

我将悬停效果放在带有圆角半径的文本块上,但是当我将鼠标移到文本块上时,悬停显示在圆角半径之外。这是我正在使用的代码:

<Border Margin="0,0,0,0"
                BorderThickness="5"
                Background="#FF7AA0CD"
                CornerRadius="8">
            <TextBlock TextWrapping="Wrap" Padding="10">
                Texto a mostrarse
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Style.Triggers>
                            <Trigger Property ="IsMouseOver" Value="True">
                                <Setter Property= "Background" Value="Green"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </Border>

1 个答案:

答案 0 :(得分:1)

你只需要将文本块中的样式更改为边框控件,如下代码:

   <Border Margin="0,0,0,0">
        <Border.Style>
            <Style TargetType="Border">
                <Setter Property="Background" Value="#FF7AA0CD"/>
                <Setter Property="BorderThickness" Value="5"/>
                <Setter Property="CornerRadius" Value="8"/>
                <Style.Triggers>
                    <Trigger Property ="IsMouseOver" Value="True">
                        <Setter Property= "Background" Value="Green"/>
                    </Trigger>
                </Style.Triggers>

            </Style>
        </Border.Style>
        <TextBlock TextWrapping="Wrap" Padding="10">
            Texto a mostrarse               
        </TextBlock>
    </Border>