我试图将背景设置为透明,但是如下截图所示,当鼠标悬停在
ListBoxItem
上时,它会在该项上显示一个蓝色矩形:
<UserControl.Resources>
<Style x:Key="HyperLinkStyle" TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground" Value="#FF0066CC"/>
<Setter Property="TextDecorations" Value="None" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="#FF0066CC"/>
<Setter Property="TextDecorations" Value="Underline" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0, 10, 0, 0">
<ListBox x:Name="TeamListView" ItemsSource="{Binding Teams}" BorderThickness="0"
SelectionMode="Single" Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</DataTemplate.Resources>
<TextBlock Margin="0, 0, 0, 5">
<Hyperlink Style="{Binding Source={StaticResource HyperLinkStyle}}"
Command="{Binding ElementName=TeamListView, Path=DataContext.ConnectToTeam}"
CommandParameter="{Binding}">
<TextBlock Text="{Binding Path=DisplayName}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
备注:
hyperlinkstyle用于为listbox中的超链接控件提供超链接效果。
列表框'TeamListView'使用ItemTemplate DataTemplate。ItemTemplate的样式是ListBoxItem,通过在鼠标悬停时将背景设置为透明,意图是去除蓝色但不改变颜色。
我错过了什么?
.NET 4.5
。 - Anatoliy Nikolaev