首页 > 解决方案 > 列表视图覆盖和突出显示列表视图项目

问题描述

我有一个包裹在 Grid 中的 ListView,在它上面有一个面板覆盖(如何在所有其他控件之上制作覆盖控件?)。我想突出显示即使光标不在其上方的列表视图项。

在此处输入图像描述

当光标位于红色矩形上方时,我希望有这样的高光。

在此处输入图像描述

<Grid Name="grid">
    <ListView Name="timeSpansListBox" SelectionMode="Extended" HorizontalAlignment="Left" Width="{Binding ElementName=timePanel, Path=ActualWidth}">
      ...
    </ListView>
    <!-- our overlay -->
    <MyPanel Name="timePanel" Panel.ZIndex="999">
      ... items (rectangles you can see on the image)
    </MyPanel>
</Grid>

我怎么能这样做?

类似问题:如何在 wpf 中单击鼠标时以较低的 zindex 获得控制?

我可以设置IsHitTestVisible为,false但我需要面板项目保持可点击状态,所以它不是一个选项。

如果只有某种方式可以以IsMouseOver编程方式设置...

标签: c#wpfxaml

解决方案


设置垂直和水平对齐以拉伸覆盖面板

<MyPanel Name="timePanel" Panel.ZIndex="999"
         HorizontalAlignment="Stretch" 
         VerticalAlignment="Stretch">
    ... items (rectangles you can see on the image)
</MyPanel>

推荐阅读