Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows8上列表框项目选择周围的白色边框_C#_Wpf_Windows 8_Listbox - Fatal编程技术网

C# Windows8上列表框项目选择周围的白色边框

C# Windows8上列表框项目选择周围的白色边框,c#,wpf,windows-8,listbox,C#,Wpf,Windows 8,Listbox,我收到了Windows8用户的投诉,他们抱怨列表框上的SelectedItem周围有一个奇怪的框架 在Windows7中,这个问题不存在,到目前为止,我还没有找到摆脱这个白色框架的方法 据我所知,Windows8列表框现在使用ControlBrushKey而不是HighlightBrushKey,但将其设置为Transparent没有任何影响 我目前没有Windows8开发环境,所以我尝试的所有修复都是纯猜测工作 列表框资源: <ListBox.Resources> &l

我收到了
Windows8
用户的投诉,他们抱怨
列表框上的
SelectedItem
周围有一个奇怪的框架

Windows7
中,这个问题不存在,到目前为止,我还没有找到摆脱这个白色框架的方法

据我所知,
Windows8
列表框现在使用
ControlBrushKey
而不是
HighlightBrushKey
,但将其设置为
Transparent
没有任何影响

我目前没有Windows8开发环境,所以我尝试的所有修复都是纯猜测工作

列表框资源:

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

     <Style TargetType="ListBoxItem">
         <Setter Property="FocusVisualStyle" Value="{x:Null}" />
         <Setter Property="BorderBrush" Value="Transparent" />
     </Style>
 </ListBox.Resources>

可以在此处找到整个Xaml:

框架图像:(选择区域周围的白色框)


如果有人知道如何摆脱它,那就太好了。

我想这可能会对你有所帮助。使用isSelected的触发器属性

 <ListBox Name="lst">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True" >
                    <Setter Property="BorderBrush" Value="Wheat"/>
                    <Setter Property="BorderThickness" Value="0"/>
                  </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>

</ListBox>

在你原来帖子的评论中,你说:

我不会因为需要覆盖的笔刷而重建控件,我只是不支持Windows8如果我需要覆盖整个ListBox模板以删除选择颜色,安装Win8后使用snoop查找笔刷将非常简单

但是,“重建”ListBoxItem并不困难。事实上,它可能比强制使用笔刷更简单,因为您不需要担心覆盖Windows版本之间的每个UX更改。我现在正在开发的一个特定应用程序要求它在XP到8.1的所有操作系统上运行;我通过自定义窗口边框的所有内容,在所有操作系统中实现了统一的外观

最好的方法是通过创建一个模板来设置
ListBoxItem
的各个方面的样式,如下所示:

<Style TargetType="ListBoxItem">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Border BorderThickness="{TemplateBinding BorderThickness}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}">
                    <ContentPresenter />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="Green" />
                    </Trigger>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="Blue" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


显然,您需要修改样式以获得所需的准确行为。

是的,最后一个答案非常有用。 这就是我如何摆脱ListBoxItem周围的白色框架的方法:

        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Style.Setters>
                    <Setter Property="BorderBrush" Value="Gray"/>
                    <Setter Property="BorderThickness" Value="0,0,0,1"/>
                    <Setter Property="Padding" Value="0"/>
                    <Setter Property="Background" Value="Black"/>
                </Style.Setters>
            </Style>
        </ListBox.ItemContainerStyle>

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Background="Black"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>


Try这是它的帮助:附加一个编译的.EXE,可以针对这个bug运行和测试什么,我将告诉您如何禁用它。@ss_ddam213链接的xaml是正确的吗?将
堆叠面板上的
方向设置为
水平
。但是,您的屏幕显示的是另一种情况。@sthotakura,它是可配置的,它有3个视图水平、垂直和Coverflow,它是在VirtualzingStackPanels触发器中设置的,所有视图都具有相同的矩形。我想我只需要安装一个Win8虚拟机,然后尝试查找问题。上传完整的项目,让我们可以尝试解决您的问题。我知道覆盖模板很简单,我只是觉得我必须这样做才能满足单个操作系统的要求很令人沮丧,当所有以前的版本都运行时,一行xaml就可以完成这个任务。@sa_ddam213:现在它可能是一个操作系统,但在未来的Windows版本中,您可能会遇到更多的问题。最好第一次就把它做好。这应该行得通。除了我会确保borderBrush设置为透明,我会添加@ViktorLaCroix:我只是告诉OP如何使用模板。说实话,我从来没有发现
的用途;没有那条线,我的风格似乎很好。