Can't change background color on new color selection

Jul 31, 2015 at 8:52 PM
Edited Jul 31, 2015 at 8:52 PM
Using a WPF application on Win7, the gridview is not available so I opted to use a ListBox instead. The xaml is shown below. It looks fine but for some reason I cannot get the selected event to trigger a change of my outer list box background. Any idea?
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Sandbox1.Views"
        xmlns:ViewModels="clr-namespace:Sandbox1.ViewModels" x:Class="Sandbox1.Views.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="487.184" Width="1260.934" WindowState="Maximized">
    <Window.Resources>

        <DataTemplate x:Key="GroupInfoTemplate">
            <WrapPanel Orientation="Vertical" Margin="10" Height="Auto" Width="263.19">
                <TextBlock Text="{Binding Name}" Foreground="White"/>
                <ListBox x:Name="listBox" Height="Auto"  Width="257.464" ItemsSource="{Binding Colors}" BorderThickness="0" HorizontalAlignment="Left" Background="Black" SelectedItem="{Binding Selected, Mode=TwoWay}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Width="202.023" Height="Auto" VerticalAlignment="Top" Margin="0,10,0,0" HorizontalAlignment="Left"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel HorizontalAlignment="Left" Margin="0,2,2,2">
                                <Rectangle Fill="{Binding Brush, Mode=OneWay}" Width="90" Height="75"/>
                                <TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="{Binding Name}" Background="{Binding Brush, Mode=OneWay}" FontSize="10.667" Foreground="#FF767272" Opacity="0.75" Width="90"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </WrapPanel>
        </DataTemplate>

        <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
            <WrapPanel/>
        </ItemsPanelTemplate>
    </Window.Resources>
    <Window.DataContext>
        <ViewModels:MainWindowViewModel/>
    </Window.DataContext>
    <Grid>
        <ListBox ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" x:Name="listBox" ItemTemplate="{DynamicResource GroupInfoTemplate}" ItemsSource="{Binding Groups}" ItemsPanel="{DynamicResource ItemsPanelTemplate1}" d:LayoutOverrides="Width" Background="{Binding Selected}"/>
    </Grid>
</Window>

This is my class:
    class MainWindowViewModel : BindableBase
    {
        public MainWindowViewModel()
        {
            var colors = typeof(Colors)
                .GetRuntimeProperties().Select(x => new Models.ColorInfo()
                {
                    Name = x.Name,
                    Color = (Color)x.GetValue(null)
                });

            _Groups.Add(new GroupInfo() { Name = "Group 1", Colors = colors.Skip(00).Take(5).ToArray() });
            _Groups.Add(new GroupInfo() { Name = "Group 2", Colors = colors.Skip(05).Take(5).ToArray() });
            _Groups.Add(new GroupInfo() { Name = "Group 3", Colors = colors.Skip(10).Take(5).ToArray() });
            _Groups.Add(new GroupInfo() { Name = "Group 4", Colors = colors.Skip(15).Take(5).ToArray() });
            _Groups.Add(new GroupInfo() { Name = "Group 5", Colors = colors.Skip(20).Take(5).ToArray() });
        }

        ObservableCollection<Models.GroupInfo> _Groups = new ObservableCollection<Models.GroupInfo>();
        public ObservableCollection<GroupInfo> Groups
        {
            get
            {
                return _Groups;
            }

            set
            {
                _Groups = value;
            }
        }


        ColorInfo _Selected = default(ColorInfo);
        public ColorInfo Selected
        {
            get { return _Selected; }
            set
            {
                SetProperty(ref _Selected, value);
                //if (!Recent.Contains(value))
                //    Recent.Insert(0, value);
                //foreach (var item in this.Recent.Skip(5))
                //    this.Recent.Remove(item);
            }
        }

    }

    public abstract class BindableBase : System.ComponentModel.INotifyPropertyChanged
    {
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (!object.Equals(storage, value))
            {
                storage = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }

        protected void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}