使元素在没有边框的情况下可测试

时间:2014-08-17 18:52:29

标签: wpf visual-studio-2012 .net-4.5

当鼠标进入元素时,是否可以使元素HitTestVisible而不显示元素周围的(蓝色)边框?

1 个答案:

答案 0 :(得分:1)

您必须覆盖RichTextBox的 ControlTemplate 才能删除该功能。

<RichTextBox Cursor="Arrow">
    <RichTextBox.Template>
        <ControlTemplate TargetType="TextBoxBase">
            <Border
                    BorderThickness="{TemplateBinding Border.BorderThickness}"
                    BorderBrush="{TemplateBinding Border.BorderBrush}"
                    Background="{TemplateBinding Panel.Background}"
                    Name="border"
                    SnapsToDevicePixels="True">
                <ScrollViewer
                    HorizontalScrollBarVisibility="Hidden"
                    VerticalScrollBarVisibility="Hidden"
                    Name="PART_ContentHost"
                    Focusable="False" />
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="UIElement.IsEnabled" Value="False">
                    <Setter Property="UIElement.Opacity"
                            TargetName="border" Value="0.56"/>
                </Trigger>
                <Trigger Property="UIElement.IsKeyboardFocused" Value="True">
                    <Setter Property="Border.BorderBrush" TargetName="border">
                        <Setter.Value>
                            <SolidColorBrush>#FF569DE5</SolidColorBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </RichTextBox.Template>
</RichTextBox>