3 回答

TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊
您需要使用ListBox.ItemContainerStyle。
ListBox.ItemTemplate指定應(yīng)如何顯示項目的內(nèi)容。但是WPF仍將每個項目包裝在ListBoxItem控件中,默認(rèn)情況下,如果選中它,則將其Background設(shè)置為系統(tǒng)突出顯示顏色。您不能停止WPF創(chuàng)建ListBoxItem控件,但是可以為它們設(shè)置樣式(在您的情況下,將Background設(shè)置為始終為Transparent或Black或其他顏色),并使用ItemContainerStyle。
juFo的答案顯示了一種可能的實現(xiàn)方式,即在項目樣式的上下文內(nèi)“劫持”系統(tǒng)背景畫筆資源;另一種可能更慣用的技術(shù)是對SetterBackground屬性使用。

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊
<UserControl.Resources>
<Style x:Key="myLBStyle" TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent"/>
</Style.Resources>
</Style>
</UserControl.Resources>
和
<ListBox ItemsSource="{Binding Path=FirstNames}"
ItemContainerStyle="{StaticResource myLBStyle}">
您只需覆蓋listboxitem的樣式(請參閱:TargetType是ListBoxItem)
- 3 回答
- 0 關(guān)注
- 1203 瀏覽
添加回答
舉報