-
Jun 10th, 2015, 07:01 PM
#1
ListView Background Color
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.
Code:
<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.
- If my post helped you, please Rate it
- If your problem is solved please also mark the thread resolved
I use VS2015 (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.
-
Jun 11th, 2015, 09:32 AM
#2
Re: ListView Background Color
Code:
<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.
- If my post helped you, please Rate it
- If your problem is solved please also mark the thread resolved
I use VS2015 (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.
-
Jun 12th, 2015, 04:10 AM
#3
Re: ListView Background Color
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.
Code:
<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>
- If my post helped you, please Rate it
- If your problem is solved please also mark the thread resolved
I use VS2015 (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.
-
Nov 4th, 2015, 06:44 PM
#4
New Member
ListView Background
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
-
Nov 12th, 2015, 03:08 PM
#5
Re: ListView Background Color
You should not bind to a color but to a brush, in your case a SolidColorBrush
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|