2012-03-14 106 views
0

我已經定義了下面的列表框,並使用發現的ShinyRed主題here。但是,如果我將鼠標懸停在標籤的文本上,我發現行顏色僅在鼠標懸停時發生變化。如果我位於列表項目的任何位置,我想讓行改變顏色。我該如何解決?爲什麼ListBoxItem在鼠標懸停時不會突出顯示?

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

回答

1

使用ListBox.ItemContainerStyle使項目拉伸。

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

(此外,如果它仍然只是反作用於文本嘗試設置Label.BackgroundTransparent擊中測試。如果它仍然不工作這一主題的ListBoxItem控制模板是有點重擊)

+0

這些想法都無效。如果我放入ItemContainerStyle中,項目是完全白色的 - 直到我將它懸停在上面,我甚至無法看到文本。任何其他想法? – bsh152s 2012-03-14 21:22:10

+0

@ bsh152s:哦,對,您需要['BasedOn'](http://msdn.microsoft.com/en-us/library/system.windows.style.basedon.aspx),因爲主題是否定的overidden。 – 2012-03-14 21:39:49

相關問題