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

mog*_*izx 3 c# wpf overlay wpf-controls

我有一个带有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>
Run Code Online (Sandbox Code Playgroud)

我的应用程序中的图像与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>
Run Code Online (Sandbox Code Playgroud)

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

Roh*_*ats 5

您可以覆盖RichTextBox template以删除默认值 -

<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>
Run Code Online (Sandbox Code Playgroud)