WPFToolkit의 AutoCompleteBox를 사용하고 있으며 선택한 항목 배경색을 변경해야하지만 할 수 없습니다. 글꼴 스타일, 글꼴 크기를 변경할 수 있습니다. 배경이 아닙니다.AutoCompleteBox 설정 ListBox SelectedItem 배경색
저는 많은 솔루션을 시도했지만 그 중 아무 것도 작동하지 않았습니다. 내가 지금까지 시도했습니다 무엇 :
:<Style x:Key="myLBStyle" TargetType="ListBoxItem">
<Setter Property="Background" Value="IndianRed" />
<Setter Property="Foreground" Value="WhiteSmoke" />
<Setter Property="Margin" Value="0" />
<Setter Property="FontSize" Value="22" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="Chartreuse" />
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="Chartreuse" />
</Trigger>
</Style.Triggers>
</Style>
<local:FocusableAutoCompleteBox x:Name="ACBox" Margin="10,32,10,0"
Grid.Row="2" FontSize="27" Grid.ColumnSpan="4" Foreground="#FF333333"
Background="#FF1700FF" BorderThickness="2" TextChanged="_ACBox_TextChanged"
KeyDown="ACBox_KeyDown" Focusable="True" MinimumPopulateDelay="100"
MinimumPrefixLength="1" ItemContainerStyle="{DynamicResource ResourceKey=myLBStyle}">
Change background color for selected ListBox item
Changing WPF Listbox SelectedItem text color and highlight/background Color using C#
가되어 selectedItem의 배경을 변경하는 트리거를 사용하여 동적으로 나는 또한 시스템 색을 무시하려고했습니다
<Style x:Key="myLBStyle" TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Green" />
</Style.Resources>
<Setter Property="Background" Value="IndianRed" />
<Setter Property="Foreground" Value="WhiteSmoke" />
<Setter Property="Margin" Value="0" />
<Setter Property="FontSize" Value="22" />
</Style>
나는 할 수있다. 트리거로 다른 속성을 정하게 설정하십시오. selecteditem의 글꼴은 기울임 꼴이며 굵게, 크게, 작게 설정할 수 있지만 선택한 항목의 배경색은 변경할 수 없습니다.
대단히 감사합니다. 그것은 효과가 있었다. 그러나 나는 그것이 효과가 있었는지 알고 싶습니까? Grid에 ListBox를 추가하고 표 배경을 설정하는 것을 이해합니다. 하지만 왜 ListBox에서 선택한 색상 자체를 변경할 수 없습니까? –
각 항목의 색상은 부모 컨트롤의 색상을 상속받지 않는 ListBoxItem에서 정의됩니다. – Iron
나는 본다. 따라서 컨트롤에는 전체 ListBox에 대한 ListBoxItem 스타일과 개별 항목을 보유하는 다른 ListBoxItem이 있습니다. –