我正在开发 Windows8 商店应用程序。我有动态填充的网格
<Grid Grid.Column="1" Margin="0,16,0,0" HorizontalAlignment="Left" VerticalAlignment="Center">
<GridView x:Name="chapterlist" HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" ItemClick="onChapterClick" Padding="0" Height="600" Margin="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Width="260" Height="80" Background="{Binding RelativeSource={RelativeSource Self}, Path=alreadyDownload, Converter={StaticResource ColorConverter}}">
<TextBlock x:Name ="AAA" Text="{Binding Path=Chapter}" FontSize="10" Foreground="White" d:LayoutOverrides="Width" Margin="5" TextWrapping="Wrap" />
<TextBlock Text="{Binding Path=Name}" Foreground="White" d:LayoutOverrides="Width" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Path=alreadyDownload}" Foreground="#073363" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,18,2,2" FontSize="10" d:LayoutOverrides="Width" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
所以我必须根据 TextBlock 值改变 StackPanel 的背景颜色,比如
<TextBlock Text="{Binding Path=alreadyDownload}" Foreground="#073363" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,18,2,2" FontSize="10" d:LayoutOverrides="Width" TextWrapping="Wrap"/>
我使用过 ColorConverter 之类的
class ColorConverter : IValueConverter
{
public object Convert(object value, System.Type targetType, object parameter, String culture)
{
if (value != null)
{
if (value.Equals("Already Downloaded "))
return Colors.Red;
else
return Colors.White;
}
return Colors.White;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
但是我的网格没有反映背景颜色(实际上根本没有颜色,它是透明的)。为什么会这样?我怎么解决这个问题?请帮助。我附上图片以供参考。提前致谢
所以我想要的是显示带有文本已经下载的网格应该有一些其他颜色,其余的网格有不同的颜色。