我有一个 ListBox,它在将鼠标悬停在一个项目上时会显示该项目的删除按钮。问题是 IsMouseOver 会在突出显示的项目中触发大约 4 个像素,因此当将鼠标悬停在多个项目上时,删除按钮似乎不会随着您上下移动,而是在项目之间的间隙中闪烁。有没有办法让 IsMouseOver 响应整个项目?
<ListBox Name="lstLength" ItemsSource="{Binding Source={StaticResource lengths}}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel LastChildFill="True" Height="22">
<Button DockPanel.Dock="Right" Name="btnDelete" Content="X" Tag="{Binding}" Click="DeleteLength" Visibility="Collapsed" />
<TextBlock Text="{Binding}" />
</DockPanel>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="btnDelete" Property="Visibility" Value="Visible" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>