# .NET and More > WPF, WCF, WF >  ListView Background Color

## Bulldog

I have a ListView where one element of the Collection is a color and the element is called "ItemColor" (of type Color). I want to set a given ListViewItem to be that color.

No matter what I try, I can't get this to work. In the example below, the Background is being set to a static color, but I want this to be something like Value= Binding(ItemColor) and the background of that item to show as being that color.



```
<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=RowSelected}" Value="True">
                <Setter Property="Background" Value="Gainsboro"  />
                <Setter Property="FontWeight" Value="Bold" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>
```

Any help appreciated.

----------


## Bulldog

```
<TextBlock Text="{Binding MyColor}" Width="80" >
    <TextBlock.Background>
        <SolidColorBrush Color="{Binding MyColor}" />
    </TextBlock.Background>
</TextBlock>
```

This also doesn't work. the Background remains the default color.

----------


## Bulldog

I got to the bottom of this and for posterity the solution is;

Assuming MyCollection has a member "Color", create an additional string member such as MyCollection.KnownColor and set it to MyCollection.Color.Name.ToString(). Then use the XML below.



```
<ListView VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name ="ListBoxResults"  
ItemsSource="{Binding Path=MyCollection}" SelectionMode="Single">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
	    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
	</Style>
    </ListView.ItemContainerStyle>
    <ListView.View>
	<GridView>
	  <GridViewColumn Header =" Colour "  Width="60" >
	    <GridViewColumn.CellTemplate>
	       <DataTemplate>
		 <TextBlock Text=Color>
			<TextBlock.Background>
		 	<SolidColorBrush Color="{Binding KnownColor}" />
			</TextBlock.Background>
		</TextBlock>
		</DataTemplate>
		</GridViewColumn.CellTemplate>
		 </GridViewColumn>
		<GridViewColumn Header=" Size "  Width="60">
		<GridViewColumn.CellTemplate>
		<DataTemplate>
		<TextBlock  Text="{Binding AnOther}" HorizontalAlignment="Center" />
		</DataTemplate>
		</GridViewColumn.CellTemplate>
		</GridViewColumn>
		</GridView> 
</ListView.View> 
</ListView>
```

----------


## Darinaskr

If you want a transparent box for the game cards, leave the background field empty, rather than specifying a color. That should make it transparent for you. 

Оффтопик: 
Как правильно variant4 
 Milliard Dollars from youtube

----------


## Lightning

You should not bind to a *color* but to a *brush*, in your case a SolidColorBrush

----------

