微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐