Listview selection color

后端 未结 1 1639
孤独总比滥情好
孤独总比滥情好 2021-01-22 11:08

I\'m playing around with wpf and I saw the following article: WPF ListView Inactive Selection Color

I want to do something similar. I want to put a border around an a li

相关标签:
1条回答
  • 2021-01-22 11:38

    Change the ItemContainerStyle on the ListView to a style that doesn't change the background when an item is selected but instead changes the color of a border. Below is an example:

      <Style x:Key="MyListViewItemStyle" TargetType="{x:Type ListViewItem}">
         <Setter Property="Background" Value="{Binding SourceType, Converter={StaticResource SourceGroupConverter}}" />
         <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="{x:Type ListViewItem}">
                  <Border
                     x:Name="Border"
                     BorderBrush="Transparent"
                     BorderThickness="1"
                     Background="{TemplateBinding Background}">
                     <GridViewRowPresenter Columns="{TemplateBinding GridView.ColumnCollection}" Content="{TemplateBinding Content}"/>
                  </Border>
                  <ControlTemplate.Triggers>
                     <Trigger Property="IsSelected" Value="true">
                        <Setter TargetName="Border" Property="BorderBrush" Value="Black"/>
                     </Trigger>
                  </ControlTemplate.Triggers>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
    

    And then use the style like this:

    <ListView ItemContainerStyle="{StaticResource MyListViewItemStyle}">
       ...
    </ListView>
    
    0 讨论(0)
提交回复
热议问题