0

我已经定义了以下 ListBox 并且正在使用在此处找到的 ShinyRed主题。但是,如果我将鼠标悬停在标签的文本上,我发现行颜色只会在鼠标悬停时发生变化。如果我在列表项行的任何位置,我想让行改变颜色。我该如何解决?

<ListBox Grid.Row="1" ItemsSource="{Binding Categories}" ScrollViewer.CanContentScroll="False">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <Label Content={Binding DisplayName}"/>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>
4

1 回答 1

1

使用ListBox.ItemContainerStyle使项目伸展。

<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListBox.ItemContainerStyle>

(另外,如果它仍然只对文本做出反应,请尝试设置Label.Background命中Transparent测试。如果它仍然不起作用ListBoxItem,则该主题的控制模板有点重击)

于 2012-03-14T21:06:28.600 回答