本文介绍了ListView项显示默认背景色在Windows 10 UWP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作在Windows 10 ListView和我想显示ListView项默认背景颜色为白色,选择的时候再灰色。我想下面的风格,但它并没有设置默认为白色。 。选中时它的工作原理
<风格X:键=TestListViewContainerStyle
的TargetType =ListViewItem的>
< setter属性=HorizontalContentAlignment
值=拉伸/>
< setter属性=保证金
值=0,0,0,1/>
< setter属性=填充
值=0/>
< setter属性=模板>
< Setter.Value>
<的ControlTemplate的TargetType =ListViewItem的>
< ListViewItemPresenter SelectedBackground =#E9E9E9
PlaceholderBackground =白
=背景白/>
< /控件模板>
< /Setter.Value>
< /二传手>
< /样式和GT;
解决方案
的背景
是从模板
独立。很好的做法,增加所有相关样式在 ListViewItemPresenter
。希望帮助
< setter属性=背景值=白/>
< setter属性=模板>
< Setter.Value>
<的ControlTemplate的TargetType =ListViewItem的>
< ListViewItemPresenter
ContentTransitions ={TemplateBinding ContentTransitions}
SelectionCheckMarkVisualEnabled =真
CheckBrush ={ThemeResource SystemControlForegroundBaseMediumHighBrush}
CheckBoxBrush ={ThemeResource SystemControlForegroundBaseMediumHighBrush }
DragBackground ={ThemeResource ListViewItemDragBackgroundThemeBrush}
DragForeground ={ThemeResource ListViewItemDragForegroundThemeBrush}
FocusBorderBrush ={ThemeResource SystemControlForegroundAltHighBrush}
FocusSecondaryBorderBrush ={ThemeResource SystemControlForegroundBaseHighBrush}
PlaceholderBackground =白
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填充}
CheckMode =内联/>
< /控件模板>
< /Setter.Value>
< /二传手>
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>
解决方案
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>
这篇关于ListView项显示默认背景色在Windows 10 UWP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!