Hi I'm trying to mimic a XAML style I found for changing the color of selection in the listbox. The XAML works great but my code behind doesn't seem to work. When I go to select an item in the list box nothing is displayed(I'm expecting a Yellow overlay). I'm hoping someone will be able to see what I'm doing wrong if I show you the XAML and the code behind I'm using to mimic it.
<Stylex:Key="SimpleListBoxItem"TargetType="ListBoxItem"><SetterProperty="Template"><Setter.Value><ControlTemplateTargetType="ListBoxItem"><BorderName="Border"Padding="2"SnapsToDevicePixels="true"><ContentPresenter/></Border><ControlTemplate.Triggers><TriggerProperty="IsSelected"Value="true"><SetterTargetName="Border"Property="Background"Value="Yellow"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
MyDataSetList.ItemContainerStyle = new Style(); Setter setter = new Setter(); setter.Property = ListBoxItem.FocusVisualStyleProperty; setter.Value = null; MyDataSetList.ItemContainerStyle.Setters.Add(setter); ControlTemplate template = new ControlTemplate(typeof(ListBoxItem)); template.VisualTree = new FrameworkElementFactory(typeof(Border)); template.VisualTree.SetValue(Border.PaddingProperty, new Thickness(6)); template.VisualTree.SetValue(Border.SnapsToDevicePixelsProperty, true); template.VisualTree.AppendChild(new FrameworkElementFactory(typeof (ContentPresenter))); Trigger trigger = new Trigger(); trigger.Property = ListBoxItem.IsSelectedProperty; trigger.Value = true; setter = new Setter(); setter.TargetName = "Border"; setter.Property = Border.BackgroundProperty; setter.Value = new SolidColorBrush(Colors.Yellow); template.Triggers.Add(trigger); setter = new Setter(); setter.Property = ListBoxItem.TemplateProperty; setter.Value = template; MyDataSetList.ItemContainerStyle.Setters.Add(setter);