लिए काम नहीं कर रहा इस प्रकार मेरी ListBox
की ItemContainerStyle
में चलाता उपयोग करते हुए मेरे ListBoxItem
रों लिए Background
संपत्ति को बदलने की कोशिश:WPF: ListBoxItem.IsSelected के लिए उत्प्रेरक पृष्ठभूमि संपत्ति
<ListBox Height="100" HorizontalAlignment="Left" Margin="107,59,0,0" Name="listBox1" VerticalAlignment="Top" Width="239">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Lightblue"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Items>
<ListBoxItem Content="First Item"/>
<ListBoxItem Content="SecondItem"/>
<ListBoxItem Content="Third Item"/>
</ListBox.Items>
</ListBox>
मैं करने के लिए नहीं चुना जाता आइटम उम्मीद करेंगे हल्के नीले रंग की पृष्ठभूमि, ढीली वस्तुओं (यानी जब माउस कर्सर उनके ऊपर होता है) पीले रंग के होते हैं और चयनित आइटम लाल होते हैं।
अचयनित और ढीले आइटमों के लिए यह अपेक्षित काम कर रहा है, लेकिन चयनित वस्तुओं में अभी भी उनके मानक पृष्ठभूमि रंग हैं (यानी नीला, यदि सूची बॉक्स में अन्यथा फोकस और हल्का भूरा है)।
क्या मुझे कुछ भी याद आ रही है? क्या यह व्यवहार कहीं दस्तावेज है?
किसी भी संकेत के लिए धन्यवाद!
संपादित
मैं डिफ़ॉल्ट प्रणाली रंग अधिभावी (हर कोई एक जवाब के रूप में इस पोस्ट करने के लिए वैसे भी Change selected and unfocused Listbox style to not be grayed out में वर्णित है, धन्यवाद) के समाधान के बारे में पता कर रहा हूँ। हालांकि यह वही नहीं है जो मैं करना चाहता हूं। मुझे और अधिक दिलचस्पी है कि मेरा समाधान क्यों काम नहीं करता है।
मैं इसे परिभाषित करने के लिए ListItem
के मानक ControlTemplate
शक कर रहा हूँ खुद चलाता जो शैली (शायद किसी को इस की पुष्टि और कुछ संसाधन जहां इस व्यवहार परिभाषित किया गया है करने के लिए मुझसे बात कर सकते हैं) द्वारा निर्धारित ट्रिगर से अधिक precendence लेने के लिए लग रहे हैं। -
<Window.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Red" />
</Window.Resources>
और अपने कोड से IsSelected उत्प्रेरक को दूर
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="Border" Padding="2" SnapsToDevicePixels="true" Background="LightBlue" Margin="0">
<ContentPresenter/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
इस अर्थ में आप अभी तक सही समाधान का उपयोग करते हैं। मानक नियंत्रण टेम्पलेट के साथ और ब्रश ओवरराइडिंग के बिना कोई समाधान नहीं। – Sonorx