C# 选择项目时更改ListViewItem内容的颜色
当选中C# 选择项目时更改ListViewItem内容的颜色,c#,wpf,xaml,listview,C#,Wpf,Xaml,Listview,当选中ListViewItem时,我想反转ListViewItem中的框架元素的颜色(Fill) 问题在于,应该具有所选颜色的FrameworkElement位于嵌套的DataTemplateSelector中的另一个DataTemplate中 例如: <ListView> <ListViewItem> <ContentPresenter> <
ListViewItem
时,我想反转ListViewItem
中的框架元素的颜色(Fill
)
问题在于,应该具有所选颜色的FrameworkElement
位于嵌套的DataTemplateSelector
中的另一个DataTemplate
中
例如:
<ListView>
<ListViewItem>
<ContentPresenter>
<ContentPresenter.ContentTemplateSelector>
<selector:IconTypeSelector>
<selector:IconTypeSelector.SuperImportantIcon>
<DataTemplate>
<Rectangle Width="27"
Height="27"
Fill="{DynamicResource ColorThatShouldChange}"><!--This is what i want to have the font color of my ListViewElements -->
</Rectangle>
</DataTemplate>
</selector:IconTypeSelector.SuperImportantIcon>
</selector:IconTypeSelector>
</ContentPresenter.ContentTemplateSelector>
</ContentPresenter>
</ListViewItem>
</ListView>
最佳情况是:
MyFrameworkElement
(示例中的矩形
)绑定在与ListViewItem
中文本的字体颜色相同的颜色上,该颜色在选中时会反转。您必须具有所选项目的索引号。在后端代码上。找到索引并设置系统。绘图,颜色由您选择
for (int i = 0; i < list.Items.Count; i++)
{
if (list.Items[i].Bounds.Contains(e.Location) == true)
{
list.Items[i].BackColor = Color.Blue; // highlighted item
}
else
{
list.Items[i].BackColor = SystemColors.Window; // normal item
}
}
for(int i=0;i
阅读并
你所要做的就是将你的颜色绑定到Bordes的背景上。类似这样的东西:for(int i=0;i