1

在 Windows 商店应用程序(c# 和 XAML)中,我可以像这样对 gridview 中的所有组应用相同的背景颜色。

<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Background" Value="#28F7E3">
</Setter>
</Style>
</GroupStyle.ContainerStyle>

上面的代码工作正常。我想用“绑定”机制应用同样的东西(因为我想对每个组应用不同的背景颜色)并且我这样编码

<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Background" Value="{Binding GroupColor}"> 
</Setter> 
</Style>
</GroupStyle.ContainerStyle>

但这不适用。在 XAML 世界中,我们可以将绑定应用到 ContainerStyle 元素吗?如何做到这一点?

我在做什么是 1)创建示例窗口存储“GridApp”。它会生成一些文件。我打开了 SampelDataSource 文件。2)创建了一个新属性“GroupColor”并设置了不同的背景颜色值 3)如上所述,绑定到 Gridview Container groupstyle XAML。

更新1:

如果我对 GroupStyle HeaderTemplate 元素做同样的事情,它会按预期应用于 groupelement。这是 GroupHeader 数据模板的代码。

<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="0">                                      
<Button Background="{Binding Path=GroupColor}" Content="{Binding MyGroupName}"></Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>

但同样的事情不适用于 Style 属性绑定。我没有收到任何错误。它只是没有附加任何我绑定的背景颜色。

4

0 回答 0