It is indeed possible to do! There are generally two ways you can go about doing this:
Firstly, you can bind the value of the background to the current list's selected item. Something like:
<ListView
Background="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Color}"
..>
In order for that particular code to work though, the item you are binding to will have to have a Color property that is either a Brush (such as SolidColorBrush) or a Color (I believe). You can get around this by using the Binding
's Converter
property and converting whatever property on the item (possibly the item itself, if it is a string) into the proper SolidColorBrush.
The second method is by adding a SelectionChanged event and changing it in the code-behind. Something like:
<ListView
SelectionChanged="ColorSelector_SelectionChanged"
..>
private void ColorSelector_SelectionChanged(object sender, SelectionChangedEventArgs args)
{
if(args.NewValue != null)
{
//Somehow get the color you need
(sender as ListView).Background = varYouGot; // the Brush you made
}
else
{
(sender as ListView).Background = defaultValue; // Some default value, possibly new SolidColorBrush(Colors.Transparent)
}
}
Hope this helps! Happy Coding!