कोई उपयोगकर्ता एक ListBoxItem पर क्लिक करता है, मैं एक साहसिक बड़ा फ़ॉन्ट लाल पृष्ठभूमि पीलामैं WPF में किसी चयनित ListBoxItem का पृष्ठभूमि रंग क्यों सेट नहीं कर सकता?
सब कुछ पृष्ठभूमि को छोड़कर काम करता है होना करने के लिए यह करना चाहते हैं। ऐसा लगता है कि चयनित आइटम के लिए एक मानक (नीली) पृष्ठभूमि है। मैं इसे कैसे ओवरराइड कर सकता हूं और चयनित पृष्ठभूमि पीले रंग को बदल सकता हूं?
<Window x:Class="AlternateListBox2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:local="clr-namespace:AlternateListBox2">
<Window.Resources>
<local:Countries x:Key="countries"/>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Content" Value="{Binding Path=Name}"/>
<Setter Property="Margin" Value="2"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Background" Value="Yellow"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ListBox
ItemsSource="{Binding Source={StaticResource countries}}"
Width="100"
Margin="10"
HorizontalAlignment="Left"
/>
</StackPanel>
</Window>
.NET 4.5 में काम नहीं करता है, http://stackoverflow.com/questions/12710296/overriding-listboxitem-background-color-when-not-in-focus-net-4-5/12710338 देखें –