Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XAML gridview中每个组的不同背景色无效_C#_Wpf_Xaml_Windows 8_Windows Store Apps - Fatal编程技术网

C# XAML gridview中每个组的不同背景色无效

C# XAML gridview中每个组的不同背景色无效,c#,wpf,xaml,windows-8,windows-store-apps,C#,Wpf,Xaml,Windows 8,Windows Store Apps,在windows应用商店应用程序(c#&XAML)中,我可以像这样将相同的背景色应用于gridview中的所有组 <GroupStyle.ContainerStyle> <Style TargetType="GroupItem"> <Setter Property="Background" Value="#28F7E3"> </Setter> </Style> </GroupStyle.ContainerStyle>

在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) 已创建示例windows应用商店“GridApp”。它将生成一些文件。我打开了SampelDataSource文件。2)创建了一个新属性“GroupColor”,并设置了不同的背景色值3)绑定到Gridview容器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>


但对于样式属性绑定来说,同样的事情不起作用。我没有得到任何错误。只是我绑定的内容没有添加任何背景色。

它给您带来了什么绑定错误?很可能是您的
DataContext
不正确,因此它找不到要绑定的属性
GroupColor
,或者
GroupColor
不是预期的数据类型(
Brush
),谢谢您的回复。我没有得到任何错误。这个GroupColor绑定正在为其他一些elments工作,我把它们放在了Group Header数据模板中以进行测试。事件我试图转换为正确的数据类型,如Brush in Style元素,但没有成功。请尝试使用类似的工具在运行时检查
DataContext
对您的
GroupItem
是什么。它还将为您突出显示任何运行时绑定错误。嗨,Rachel,我在我的windows 8计算机上安装了Snoop。但没有按预期工作(可能是我没有正确使用此工具)。此工具是否支持windows 8 metro应用程序?我不确定,我还没有在windows 8上尝试过。我知道有两个版本,32位版本与64位操作系统不兼容。史努比的另一个选择是,但我从未亲自尝试过,我只听说过。