wpf ListView -禁用标题鼠标

时间:2022-07-04 14:46:45

I have a simple 1 column ListView and I need to disable the mouse over effect for the GridViewColumnHeader.

我有一个简单的列ListView,我需要禁用鼠标对GridViewColumnHeader的效果。

I tried grabbing the style from here: http://msdn.microsoft.com/en-us/library/ms788747.aspx

我尝试从这里获取样式:http://msdn.microsoft.com/en-us/library/ms788747.aspx

However that gave my header a purple gradient so I guess it was the wrong style. I do notice it has a

但是这给了我的标题一个紫色的渐变,所以我猜这是错误的风格。我注意到它有一个

<VisualState x:Name="MouseOver">

But I have no idea how to remove that without finding and including the correct GridViewColumnHeader style and then removing it.

但是我不知道如何删除它,除非找到并包含正确的GridViewColumnHeader样式,然后删除它。

I tried the following, but it doesn't do anything (The VisualState overrides?) and wouldn't work anyway as setting the background to null wouldn't be what I want.

我尝试了下面的方法,但它并没有做任何事情(VisualState重写?),而且不管怎样,将背景设置为null并不是我想要的。

       <Style x:Key="hcs" TargetType="{x:Type GridViewColumnHeader}">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{x:Null}" />
                    <Setter Property="BorderBrush" Value="{x:Null}" />
                </Trigger>
            </Style.Triggers>
        </Style>

1 个解决方案

#1


0  

The problem is, like you said yourself, in MouseOver visual state and its Storyboard. I think it`s better to get rid from redundant functionality than try to override it later. So we basically just need the same style but without that storyboard. For bare minimum we need to have following things (can be found on MSDN via the link you provided):

问题是,就像你说的,在MouseOver视觉状态和它的故事板。我认为摆脱冗余功能比稍后尝试重写要好。我们基本上只需要相同的样式但是没有故事板。至少,我们需要以下东西(可以通过您提供的链接在MSDN上找到):

 <Color x:Key="BorderLightColor">#FFCCCCCC</Color>
 <Color x:Key="BorderDarkColor">#FF444444</Color>

 <Style x:Key="GridViewColumnHeaderGripper"
           TargetType="Thumb">
      <!-- Full GridViewColumnHeaderGripper style here  -->
 </Style>

 <Style TargetType="GridViewColumnHeader">
     <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="GridViewColumnHeader">
              <!-- Standard template but with redundant Storyboard removed -->
          </ControlTemplate>
        </Setter.Value>
     </Setter>
  </Style>

The last Style doesn`t have a key so it applies to all GridViewColumnHeader on page \ application (depends on where it is defined). Or you can set the key and use it only in specific grids.

最后一个样式没有键,因此它适用于页面\应用程序上的所有GridViewColumnHeader(取决于它的定义)。或者你可以设置密钥,只在特定的网格中使用它。

That`s bare minimum so for more customizable approach it may be better to copy other parts of default style too.

这是最低限度的,因此对于更可定制的方法,最好也复制默认样式的其他部分。

#1


0  

The problem is, like you said yourself, in MouseOver visual state and its Storyboard. I think it`s better to get rid from redundant functionality than try to override it later. So we basically just need the same style but without that storyboard. For bare minimum we need to have following things (can be found on MSDN via the link you provided):

问题是,就像你说的,在MouseOver视觉状态和它的故事板。我认为摆脱冗余功能比稍后尝试重写要好。我们基本上只需要相同的样式但是没有故事板。至少,我们需要以下东西(可以通过您提供的链接在MSDN上找到):

 <Color x:Key="BorderLightColor">#FFCCCCCC</Color>
 <Color x:Key="BorderDarkColor">#FF444444</Color>

 <Style x:Key="GridViewColumnHeaderGripper"
           TargetType="Thumb">
      <!-- Full GridViewColumnHeaderGripper style here  -->
 </Style>

 <Style TargetType="GridViewColumnHeader">
     <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="GridViewColumnHeader">
              <!-- Standard template but with redundant Storyboard removed -->
          </ControlTemplate>
        </Setter.Value>
     </Setter>
  </Style>

The last Style doesn`t have a key so it applies to all GridViewColumnHeader on page \ application (depends on where it is defined). Or you can set the key and use it only in specific grids.

最后一个样式没有键,因此它适用于页面\应用程序上的所有GridViewColumnHeader(取决于它的定义)。或者你可以设置密钥,只在特定的网格中使用它。

That`s bare minimum so for more customizable approach it may be better to copy other parts of default style too.

这是最低限度的,因此对于更可定制的方法,最好也复制默认样式的其他部分。