我想根据页面更改GridView的所选项目背景颜色。我在每个ViewModels中定义一个Color属性,然后将ViewModel分配给视图的DataContext。我在app.xaml中编辑ItemContainerStyle并想要将ViewModel的color属性绑定到selectionbackground,以便所选项目的背景颜色在每个视图中都不同,但它不起作用,我看不到预期的颜色。有人可以帮忙吗?
答案 0 :(得分:0)
如果我们在app.xaml页面中应用样式,它们将适用于我们的所有应用程序。
我认为您可以通过在页面中使用“UserControl.Resources”在页面级别定义资源来实现此目的。
<UserControl.Resources>
<Style TargetType="...">
...
</Style>
</UserControl.Resources>
您甚至可以在样式中设置键属性并应用于控件,如下面的
<UserControl.Resources>
<Style x:Key="my_key" TargetType="...">
....
</Style>
</UserControl.Resources>