【发布时间】:2011-09-16 21:16:56
【问题描述】:
我正在尝试设计一些漂亮的列表框,但每次我点击列表框中的项目 选择背景毁了一切...... 我怎样才能让它无关紧要?
这是 XAML:
<!-- Site List View -->
<ListBox Grid.Row="1" Name="SiteListBox" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch">
<ListBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="Gainsboro" Offset="0.805" />
</LinearGradientBrush>
</ListBox.Background>
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="Control.Padding" Value="0"></Setter>
<Style.Triggers>
<Trigger Property="ListBoxItem.IsSelected" Value="True">
<Setter Property="ListBoxItem.Background" Value="DarkRed" />
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="4"
Background="{Binding Path=Background, RelativeSource={
RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ListBoxItem}
}}">
<TextBlock Margin="5" Text="{Binding Path=Name}" />
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
a 还附上了打印屏幕。
【问题讨论】:
-
您最好的选择是重新定义所选项目的颜色。见这里:stackoverflow.com/questions/388232/…
-
@Matt Hamilton:刚刚注意到你的回答和我一样,只是在评论中。你应该发布一个答案,并不是要窃取你的答案:)
-
@Meleak 认为复制内容不值得。