在Windows 10 UWP中显示ListView项的默认背景颜色?(Display default background color of ListView Item in Windows 10 UWP?)
我正在使用Windows 10 ListView,我希望将ListView项目默认背景颜色显示为白色,然后选择灰色。 我试过跟随Style但它没有将默认设置为白色。 它在选择时有效。
<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>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>最满意答案
Background与Template分开。 在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>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>更多推荐
White,ListView,Style,电脑培训,计算机培训,IT培训"/> <meta name="descript
发布评论