c# – 禁用/覆盖WPF控件上的突出显示

我有一个带有ScrollViewer.VerticalScrollBarVisibility = Auto的RichTextBox,这就像我想要的那样工作.但是,当我将鼠标悬停在文档上时,我在整个RichTextBox元素周围得到一个蓝色边框,而我似乎唯一能让它消失的方法是设置IsHitTestVisible = false,但如果我这样做,滚动条也会被禁用…我尝试过的其他事情是IsFocusable = false并触发RichTextBox的样式,但没有任何成功:

<Style.Triggers>
    <Trigger Property="IsMouSEOver" Value="True">
        <Setter Property="BorderBrush" Value="{x:Null}"/>
    </Trigger>
</Style.Triggers>

我的应用程序中的图像与ListBox显示的问题相同.我有一个ListBox看起来像这样:

<ListBox ItemsSource="{Binding Photos}"
         BorderBrush="{x:Null}"
         SelectedItem="{Binding SelectedPhoto,Mode=TwoWay}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid IsItemsHost="True" 
                         HorizontalAlignment="Center" 
                         VerticalAlignment="Center" 
                         Columns="3" Rows="1"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding}" 
                   Stretch="Uniform" 
                   SnapsToDevicePixels="True"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>
        <Style targettype="ListBoxItem">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                                 Color="Transparent"/>
            </Style.Resources>
            <Setter Property="Foreground" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="{StaticResource Brush_Secondary}"/>
            <Setter Property="BorderThickness" Value="5"/>
            <Setter Property="Margin" Value="5"/>
            <Style.Triggers>
                <Trigger Property="IsMouSEOver" Value="True">
                    <Setter Property="BorderBrush" Value="{StaticResource Brush_Primary}"/>
                </Trigger>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="BorderBrush" Value="{StaticResource Brush_Selected}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

但无论我使用哪种颜色(Brush_Primary / Secondary / Selected),边框总是只有不同的蓝色阴影……如何摆脱每个WPF控件似乎存在的蓝色叠加/突出显示

解决方法

您可以覆盖RichTextBox模板以删除认值 –

<Style targettype="RichTextBox">
   <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Border x:Name="Bd"
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        BorderThickness="{TemplateBinding BorderThickness}"
                        SnapsToDevicePixels="True"
                        Background="{TemplateBinding Background}">
                    <ScrollViewer Name="PART_ContentHost"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...