在 ListView 中更改颜色
change color in ListView
当 Listview
项目为 selected
时,我正在尝试更改边框背景。
<Border x:Name="myback" Background="Transparent">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
根据你的代码,我想知道 Border 是否在 ListViewItem 的模板中,如果是,请转到以下路径:C:\Program Files (x86)\Windows Kits\DesignTime\CommonConfiguration\Neutral\UAP.0.14393.0\Generic\generic.xaml 获取所有 UWP 控件的所有默认样式。
然后请搜索 ListViewItem 样式,您会找到两个 ListViewItem 样式,请将名为 ListViewItemExpanded 的样式复制到您的项目中,并在 旁边添加边框ListViewItemExpanded 样式。
之后,为了在选择 ListViewItem 时更改边框背景,请搜索 Selected/PointerOverSelected/PressedSelected VisualState 并添加以下 XAML 代码在里面改变颜色:
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="myback" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
</ObjectAnimationUsingKeyFrames>
当 Listview
项目为 selected
时,我正在尝试更改边框背景。
<Border x:Name="myback" Background="Transparent">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
根据你的代码,我想知道 Border 是否在 ListViewItem 的模板中,如果是,请转到以下路径:C:\Program Files (x86)\Windows Kits\DesignTime\CommonConfiguration\Neutral\UAP.0.14393.0\Generic\generic.xaml 获取所有 UWP 控件的所有默认样式。 然后请搜索 ListViewItem 样式,您会找到两个 ListViewItem 样式,请将名为 ListViewItemExpanded 的样式复制到您的项目中,并在 旁边添加边框ListViewItemExpanded 样式。
之后,为了在选择 ListViewItem 时更改边框背景,请搜索 Selected/PointerOverSelected/PressedSelected VisualState 并添加以下 XAML 代码在里面改变颜色:
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="myback" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
</ObjectAnimationUsingKeyFrames>