加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:57:44 所属栏目:百科 来源:网络整理
导读:我有一个带有ScrollViewer.VerticalScrollBarVisibility = Auto的RichTextBox,这就像我想要的那样工作.但是,当我将鼠标悬停在文档上时,我在整个RichTextBox元素周围得到一个蓝色边框,而我似乎唯一能让它消失的方法是设置IsHitTestVisible = false,但如果我这
我有一个带有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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读