禁用蓝色边框为选定的ListView项 [英] Disable blue border for selected Listview item

查看:140
本文介绍了禁用蓝色边框为选定的ListView项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有水平WrapPanel为ItemsPanelTemplate一个ListView。
我想摆脱的蓝色背景选定项目。它是可见只有在选定项目的左侧。

有这么多类似的问题,我尝试了很多的解决方案,并没有一次成功。

这是我已经尝试过:

 < ListView.Resources>
            <风格的TargetType ={X:类型的ListViewItem}>
                < Style.Resources>
                    <! - 前景为所选的ListViewItem - >
                    <的SolidColorBrush X:键={X:静态SystemColors.HighlightTextBrushKey}
                             颜色=黑/>
                    <! - 背景所选的ListViewItem - >
                    <的SolidColorBrush X:键={X:静态SystemColors.HighlightBrushKey}
                             颜色=透明/>
                    <! - 的SelectedItem没有焦点 - >
                    <的SolidColorBrush X:键={X:静态SystemColors.ControlBrushKey}颜色=透明/>
                < /Style.Resources>
            < /样式和GT;
        < /ListView.Resources>< ListView.ItemContainerStyle>
            <风格的TargetType ={X:类型的ListViewItem}>
                < EventSetter事件=Control.MouseDoubleClick处理器=HandleSelectedItemDoubleClick/>
                < Style.Triggers>
                    <触发属性=IsSelectedVALUE =真正的>
                        < setter属性=的RenderTransform>
                            < Setter.Value>
                                &所述; ScaleTransform的ScaleX =2的scaleY =2的centerX =12CenterY =12/>
                            < /Setter.Value>
                        < /二传手>
                        < setter属性=Panel.ZIndexVALUE =150/>
                        < setter属性=FocusVisualStyleVALUE ={X:空}/>
                        < setter属性=BorderBrushVALUE ={X:空}/>
                        < setter属性=背景VALUE ={X:空}/>
                    < /触发>
                < /Style.Triggers>
            < /样式和GT;
        < /ListView.ItemContainerStyle>
        < ListView.ItemsPanel>
            < ItemsPanelTemplate>
                < WrapPanel方向=横向WIDTH =210保证金=15/>
            < / ItemsPanelTemplate>
        < /ListView.ItemsPanel>


解决方案

您需要覆盖 SystemColors.HighlightBrushKey 的ListView 透明(或任何你想要的颜色)

我通常把这个在 ListView.Resources 所以它仅适用于特定的的ListView ,而不是所有列表视图在我的应用

 < ListView.Resources>
    <的SolidColorBrush X:键={X:静态SystemColors.HighlightBrushKey}
                     颜色=透明/>
< /ListView.Resources>

它非常接近你在你的code什么了,但你需要将其设置为 ListView.Resources ,而不是 ListViewItem.Resources

I have a ListView with Horizontal WrapPanel as its ItemsPanelTemplate. I want to get rid of the blue background for selected item. It is visible only on the left of the selected item.

There are many similar question on SO and I tried a lot of the solutions and none of them worked.

This is what I have already tried:

<ListView.Resources>
            <Style TargetType="{x:Type ListViewItem}">
                <Style.Resources>
                    <!-- Foreground for Selected ListViewItem -->
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" 
                             Color="Black"/>
                    <!-- Background for Selected ListViewItem -->
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                             Color="Transparent"/>
                    <!--SelectedItem without focus-->
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                </Style.Resources>
            </Style>
        </ListView.Resources>



<ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <EventSetter Event="Control.MouseDoubleClick" Handler="HandleSelectedItemDoubleClick"/>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="RenderTransform">
                            <Setter.Value>
                                <ScaleTransform ScaleX="2" ScaleY="2" CenterX="12" CenterY="12" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Panel.ZIndex" Value="150"/>
                        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                        <Setter Property="BorderBrush" Value="{x:Null}" />
                        <Setter Property="Background" Value="{x:Null}" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal" Width="210" Margin="15" />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>

解决方案

You need to overwrite the SystemColors.HighlightBrushKey for the ListView to be Transparent (or whatever color you want)

I typically put this in the ListView.Resources so it only applies to the specific ListView, and not all ListViews in my application

<ListView.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                     Color="Transparent"/>
</ListView.Resources>

Its very close to what you have in your code already, but you need to set it for the ListView.Resources, not ListViewItem.Resources

这篇关于禁用蓝色边框为选定的ListView项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆