当IsEnabled为false时,ListView周围的边框

时间:2012-01-26 12:22:53

标签: wpf xaml isenabled systemcolors

IsEnabled上设置FalseListView时,控件周围会出现一个像素厚的边框,颜色为#F0F0F0(在Win7上)。

我怀疑它是SystemColors踢的其中之一。如何将此边框BorderThickness设置为0,或者失败,SystemColors我可以覆盖我的样式,将其更改为与控件背景相同的颜色吗?

我确信这里有多余的行,因为我一直在添加和删除试图解决问题的东西

<ListView ItemsSource="{Binding Path=Types}" SelectedItem="{Binding Path=SelectedType}" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsEnabled="{Binding Path=TypeCategoryIsSelected}" ItemContainerStyle="{StaticResource LVItemStyle}" BorderThickness="0" Background="{StaticResource aBackground}" SelectionMode="Single">


</ListView>

<SolidColorBrush x:Key="aBackground" Color="#FFFFE7" />

<DataTemplate x:Key="tDefaultTemplate">
    <Border BorderBrush="#CDCDCD" BorderThickness="1" Background="#FFFFFF" Width="325" Margin="15,2,15,2" HorizontalAlignment="Stretch">
        <DockPanel Margin="1,1,1,1" Height="28" HorizontalAlignment="Stretch" Width="Auto">
            <DockPanel.Background>
                <LinearGradientBrush StartPoint="1,0" EndPoint="1,1">
                    <GradientStop Color="#F2EFEF" Offset="0.0" />
                    <GradientStop Color="#F6F5F5" Offset="0.5" />
                    <GradientStop Color="#F8F8F8" Offset="1.0" />
                </LinearGradientBrush>
            </DockPanel.Background>
            <TextBlock Margin="20,0,0,0" DockPanel.Dock="Left" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Path=Name}" />
        </DockPanel>
    </Border>
</DataTemplate>

<DataTemplate x:Key="tSelectedTemplate">
    <Border BorderBrush="#DDA4AB" BorderThickness="1" Background="#FFFFFF" Width="325" Margin="15,2,15,2" HorizontalAlignment="Stretch">
        <DockPanel Margin="1,1,1,1" Height="28" HorizontalAlignment="Stretch" Width="Auto">
            <DockPanel.Background>
                <LinearGradientBrush StartPoint="1,0" EndPoint="1,1">
                    <GradientStop Color="#FFE0E3" Offset="0.0" />
                    <GradientStop Color="#FFE8EA" Offset="0.5" />
                    <GradientStop Color="#F6EAEB" Offset="1.0" />
                </LinearGradientBrush>
            </DockPanel.Background>
            <TextBlock Margin="20,0,0,0" DockPanel.Dock="Left" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Path=Name}" />
        </DockPanel>
    </Border>
</DataTemplate>

<Style TargetType="{x:Type ListViewItem}" x:Key="LVItemStyle">
    <Setter Property="ContentTemplate" Value="{StaticResource tDefaultTemplate}" />
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFFFE7"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FFFFE7" />
    </Style.Resources>
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="ContentTemplate" Value="{StaticResource tSelectedTemplate}" />
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="{StaticResource aBackground}" />
        </Trigger>
    </Style.Triggers>
</Style>

<Style TargetType="{x:Type ListView}" x:Key="LVStyle">
    <Setter Property="Background" Value="{StaticResource aBackground}" />
    <Setter Property="BorderThickness" Value="0" />
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFFFE7"/>
    </Style.Resources>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="BorderBrush" Value="#FFFFE7"/>
            <Setter Property="Background" Value="{StaticResource aBackground}" />
        </Trigger>
    </Style.Triggers>
</Style>

1 个答案:

答案 0 :(得分:1)

好的,我已经做了一些调查,并设法找到问题的原因(和运行时解决方案)。我已经没时间了,所以我会透露我的调查结果,希望你能完成调查。

首先,我使用了一个名为Snoop的工具,它允许您深入挖掘渲染的WPF并查看所有控件的值并显示每个图层。使用此功能,我设法发现您的ListView控件包含Border控件。 Border的{​​{1}}值为Padding,这是您边境的来源(见下文)。使用Snoop更改运行时属性值的功能,我将其设置为1,果然,边框已经消失。

Cause of issue as seen through Snoop

有可能,你可以在0的某个地方控制它。要么,或者您正在使用的其中一种样式正在引起它。我会在没有任何设置的Style上尝试(除了一些基本项目,大小和禁用)。这可以帮助您了解它是由您造成的还是ListView控件内部的内容。

如果您无法直接找到解决此问题的方法,可以尝试通过创建自己的ControlTemplate来模仿ListView控件,这样您就可以完全控制它的渲染方式(虽然这可能会成为一项相当大的工作)。

相关问题