【问题标题】:Display default background color of ListView Item in Windows 10 UWP?在 Windows 10 UWP 中显示 ListView 项的默认背景颜色?
【发布时间】:2016-06-01 21:03:46
【问题描述】:

我正在使用 Windows 10 ListView,我想将 ListView 项目的默认背景颜色显示为白色,然后选择灰色。我尝试遵循样式,但没有将默认设置为白色。选中后即可使用。

<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>

【问题讨论】:

  • 试试这个&lt;Style TargetType="ListViewItem"&gt; &lt;Setter Property="Background" Value="White"/&gt;&lt;/Style&gt;
  • 不。我还没有研究过。

标签: c# xaml windows-10-universal


【解决方案1】:

BackgroundTemplate 是分开的。在ListViewItemPresenter 中添加所有相关样式的良好做法。希望有帮助

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 2020-06-27
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多