1

我正在使用带有 WPF 的列表视图,我想删除鼠标悬停时的突出显示颜色,我正在实现此代码。

 <Trigger Property="IsMouseOver" Value="True">
       <Setter Property="Background" Value="Transparent" />
 </Trigger>

虽然它正在移除高亮颜色但不是完全移除,但列表视图项目顶部有一个灰色的小矩形框,我怎样才能完全移除这个高亮?

下面也是附上的图片。

http://i.stack.imgur.com/8uvsi.png

4

3 回答 3

4

Altamash,据我了解,出现白线的原因是 wpf 使用的是包含该配色方案的默认 Windows Aero 主题。为了修改它,您可以为您的 ListViewItem 编写自己的控件

默认颜色

修改配色方案后

<ListView.ItemContainerStyle>
     <Style TargetType="{x:Type ListViewItem}">
           <Style.Resources>
                <SolidColorBrush x:Key="ListItemHoverFill" Color="LightBlue"/>
           </Style.Resources>
           <Setter Property="Template">
                <Setter.Value>
                     <ControlTemplate TargetType="{x:Type ListViewItem}">
                          <Border CornerRadius="0" SnapsToDevicePixels="True"  
                              BorderThickness="0,-1,0,1"   
                              BorderBrush="#dcdbd5"   
                              Background="{TemplateBinding Background}">
                                  <Border Name="InnerBorder" CornerRadius="0" BorderThickness="0">
                                      <Grid>
                                          <Rectangle Name="UpperHighlight" Visibility="Collapsed" Fill="Transparent" />
                                          <GridViewRowPresenter Grid.RowSpan="0"   
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"   
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                      </Grid>
                                  </Border>
                             </Border>
                       <ControlTemplate.Triggers>
                       <Trigger Property="IsMouseOver" Value="True">
                           <Setter Property="Background" Value="{StaticResource ListItemHoverFill}" />
                           <Setter Property="BorderBrush" Value="Transparent" />
                           <Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" />
                       </Trigger>

                   </ControlTemplate.Triggers>
               </ControlTemplate>
           </Setter.Value>
        </Setter>
     </Style>
</ListView.ItemContainerStyle>

希望这可以帮助 ;)

于 2013-09-05T06:29:45.750 回答
1

也许设置项目容器的样式

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Control.Focusable" Value="False"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{x:Null}" />
                <Setter Property="BorderBrush" Value="{x:Null}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

或者您可以使用多触发器

<MultiTrigger.Conditions>
    <Condition Property="IsSelected" Value="false"/>
    <Condition Property="IsMouseOver" Value="true"/>
</MultiTrigger.Conditions>
于 2013-09-03T21:56:58.837 回答
0

我的解决方案是设置古典主题:

        public static void SetTheme(string themeName, string themeColor)
    {
        const BindingFlags staticNonPublic = BindingFlags.Static | BindingFlags.NonPublic;

        var presentationFrameworkAsm = Assembly.GetAssembly(typeof(Window));

        var themeWrapper = presentationFrameworkAsm.GetType("MS.Win32.UxThemeWrapper");

        var isActiveField = themeWrapper.GetField("_isActive", staticNonPublic);
        var themeColorField = themeWrapper.GetField("_themeColor", staticNonPublic);
        var themeNameField = themeWrapper.GetField("_themeName", staticNonPublic);

        // Set this to true so WPF doesn't default to classic.
        isActiveField.SetValue(null, true);

        themeColorField.SetValue(null, themeColor);
        themeNameField.SetValue(null, themeName);
    }

    static App()
    {
        try
        {
            SetTheme("Classic", "NormalColor");

资料来源: http: //northhorizo​​n.net/2010/how-to-actually-change-the-system-theme-in-wpf/

于 2015-04-15T11:54:39.690 回答