Wpf 帮助为ListBoxItem创建样式
我不熟悉样式,需要帮助为ListBoxItem创建一个样式,该样式将为该项目提供透明背景,然后将字体悬停在上方时变为金色。它不应在单击时更改颜色,并在鼠标移开时恢复正常。它仍然必须将所选对象传递给列表框的PreviewMouseRightButtonDown事件 我目前使用的是REUXABLES主题的默认字典,但这是在应用程序上显示这部分内容的一种方式 谢谢Wpf 帮助为ListBoxItem创建样式,wpf,formatting,listboxitem,Wpf,Formatting,Listboxitem,我不熟悉样式,需要帮助为ListBoxItem创建一个样式,该样式将为该项目提供透明背景,然后将字体悬停在上方时变为金色。它不应在单击时更改颜色,并在鼠标移开时恢复正常。它仍然必须将所选对象传递给列表框的PreviewMouseRightButtonDown事件 我目前使用的是REUXABLES主题的默认字典,但这是在应用程序上显示这部分内容的一种方式 谢谢 <DataTemplate x:Key="ItemsTemplate"> <StackPanel
<DataTemplate x:Key="ItemsTemplate">
<StackPanel Orientation="Vertical"
Margin="0,5,0,5"
Width="{Binding
Path=ActualWidth,
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ScrollContentPresenter}}}" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}" >
<TextBlock VerticalAlignment="Top" TextWrapping="Wrap" FontSize="14" Text="{Binding Path=CID}" />
<StackPanel Orientation="Horizontal" Margin="0,5,0,0" >
<TextBlock>
<Label Foreground="{DynamicResource DisabledForegroundBrush}" >Posted by</Label>
<Label Foreground="{DynamicResource DisabledForegroundBrush}" VerticalContentAlignment="Top" Content="{Binding Path=ACID}" />
</TextBlock>
<TextBlock>
<Label Foreground="{DynamicResource DisabledForegroundBrush}" Margin="3,0,0,0">at</Label>
<Label Foreground="{DynamicResource DisabledForegroundBrush}" Margin="3,0,3,0" VerticalContentAlignment="Top" Content="{Binding Path=Type}" />
</TextBlock>
<TextBlock>
<Label Foreground="{DynamicResource DisabledForegroundBrush}">(</Label>
<Label Foreground="{DynamicResource DisabledForegroundBrush}" VerticalContentAlignment="Top" Content="{Binding Path=Route}" />
<Label Foreground="{DynamicResource DisabledForegroundBrush}">)</Label>
</TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
<Style x:Key="ItemsListBox" TargetType="{x:Type ListBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Background" Value="{DynamicResource Transparent}"/>
<Setter Property="BorderBrush" Value="{DynamicResource Transparent}"/>
<Setter Property="BorderBrush" Value="{DynamicResource Transparent}"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
</Style>
<ListBox x:Name="ListViewFlightPlans" Grid.Column="0" ItemTemplate="{DynamicResource ItemsTemplate}"
MaxWidth="800" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderBrush="Black" BorderThickness="2,0,0,1">
</ListBox>
邮寄人
在
(
)
Dave不幸的是,为
ListBoxItem
更改BorderBrush
不会产生您想要的效果,因为带有选择突出显示的边框
位于ListBoxItem
的控制模板
内部
相反,您可以使用的键添加一个新的笔刷
资源,这是ListBoxItem
用于设置选择突出显示颜色的键
非活动选择笔刷使用的键,因此如果使用透明的笔刷覆盖这两个选项,则可以保证没有任何选择颜色。您可以在中阅读更多关于它的信息
下面是一个示例,介绍了除您的数据模板之外的所有内容:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid.Resources>
<x:Array x:Key="data" Type="{x:Type sys:String}">
<sys:String>a </sys:String>
<sys:String>bb</sys:String>
<sys:String>ccc</sys:String>
<sys:String>dddd</sys:String>
</x:Array>
</Grid.Resources>
<ListBox ItemsSource="{StaticResource data}">
<ListBox.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Gold"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
</ListBox>
</Grid>
A.
bb
ccc
dddd