以下是我的问题:
<Style x:Key="listbox_minecraft_container_style" TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="{DynamicResource image_listbox_item_background}"/>
<Setter Property="Margin" Value="1"/>
<Setter Property="BorderBrush" Value="#FF8B8B8B"/>
<Setter Property="BorderThickness" Value="0.4"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Width" Value="180"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource image_listbox_item_background_fulopacity}"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="#FF42A855"/>
</Trigger>
</Style.Triggers>
</Style>
如果我现在点击一个
ListBoxItem
,它的背景属性不会被正确地设置。它会设置新的Foreground
和新的FontWeight
,但不会设置Background
。这是我在
MainWindow
中的ListBox
:<ListBox x:Name="listBox_vanilla_versions"
Style="{StaticResource listbox_minecraft}"
ItemContainerStyle="{StaticResource listbox_minecraft_container_style}"
Margin="10,122,484.592,198.5">
<ListBox.Items>
<ListBoxItem Content="hi"/>
</ListBox.Items>
</ListBox>