我正在尝试将背景设置为透明,但是正如您在下面的屏幕截图中看到的那样,当鼠标悬停在ListBoxItem
它上面时,它会在项目上显示一个蓝色矩形:
我正在使用 MVVM,我的实现如下:
<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 用于在列表框中为超链接控件提供超链接感觉。
列表框“TeamListView”使用 ItemTemplate DataTemplate。ItemTemplate 的样式是 ListBoxItem,通过将背景设置为透明 onMouseHover 目的是在悬停时移除没有颜色的蓝色。
我错过了什么?