0

我想根据页面更改我的 GridView 的选定项目背景颜色。我在每个 ViewModel 中定义了一个 Color 属性,然后将 ViewModel 分配给视图的 DataContext。我在 app.xaml 中编辑 ItemContainerStyle 并想将 ViewModel 的颜色属性绑定到 selectionbackground,以便每个视图中所选项目的背景颜色不同,但它不起作用,我看不到预期的颜色。任何人都可以帮忙吗?

4

1 回答 1

0

如果我们在 app.xaml 页面中应用样式,它们将应用于我们的所有应用程序。

我认为您可以通过在页面中使用“UserControl.Resources”在页面级别定义资源来做到这一点。

<UserControl.Resources>
    <Style TargetType="...">
     ...
    </Style>
</UserControl.Resources>

您甚至可以在样式中设置关键属性并应用到控件,如下所示

    <UserControl.Resources>
    <Style x:Key="my_key" TargetType="...">
    ....
    </Style>
</UserControl.Resources>
于 2013-06-13T09:42:29.133 回答