Display default background color of ListView Item in Windows 10 UWP?

梦想的初衷 提交于 2019-12-12 03:28:46

问题


I am working on Windows 10 ListView and I want to display ListView Item default background color as White and when select then gray. I tried following Style but it didn't set default as White. It works when selected.

<Style x:Key="TestListViewContainerStyle"
       TargetType="ListViewItem">
    <Setter Property="HorizontalContentAlignment"
            Value="Stretch" />
    <Setter Property="Margin"
            Value="0,0,0,1"/>
    <Setter Property="Padding"
            Value="0"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListViewItem">
                <ListViewItemPresenter SelectedBackground="#E9E9E9"
                                       PlaceholderBackground="White"
                                       Background="White"/>

            </ControlTemplate>
        </Setter.Value>
    </Setter>

</Style>

回答1:


The Background is seperate from the Template. Good practice to add all the relevant styles in your ListViewItemPresenter. Hope that helps

<Setter Property="Background" Value="White"/>
<Setter Property="Template">
   <Setter.Value>
    <ControlTemplate TargetType="ListViewItem">
      <ListViewItemPresenter
         ContentTransitions="{TemplateBinding ContentTransitions}"
         SelectionCheckMarkVisualEnabled="True"
          CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
          CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
          DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
          DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
          FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
          FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
          PlaceholderBackground="White"
          PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
          PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
          SelectedBackground="#E9E9E9"
          SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
          SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
          PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
          SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
          DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
          DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
          ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
          HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
          ContentMargin="{TemplateBinding Padding}"
          CheckMode="Inline"/>
    </ControlTemplate>
  </Setter.Value>
</Setter>


来源:https://stackoverflow.com/questions/37568516/display-default-background-color-of-listview-item-in-windows-10-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!