2008-12-11 20 views

回答

2

我认为使用IValueConverter是合适的解决方案。您可以制作一个将字符串十六进制值转换为Color的HexConverter。该链接应该让你开始。

6

你会想要使用一个样式绑定ListViewItem的背景到该行的项目。该项目是一个ListViewItem的默认的DataContext所以这应该是简单的:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid.Resources> 
     <x:Array x:Key="colors" Type="{x:Type sys:String}"> 
      <sys:String>Red</sys:String> 
      <sys:String>Yellow</sys:String> 
      <sys:String>#0000FF</sys:String> 
     </x:Array> 
    </Grid.Resources> 
    <ListView ItemsSource="{StaticResource colors}"> 
     <ListView.Resources> 
      <Style TargetType="{x:Type ListViewItem}"> 
       <Setter Property="Background" Value="{Binding .}"/> 
      </Style> 
     </ListView.Resources> 
    </ListView> 
</Grid> 

而是结合整个项目,你会绑定到BACKGROUNDCOLOR,但它应该是类似于以上。你必须使用带有绑定的转换器作为前缀“#”,这是内置BrushConverter将其解析为十六进制的信号。

相关问题