将 IsHitTestVisible 设置为 false 会影响 wpf 中的光标

Setting IsHitTestVisible to false affects the cursor in wpf

我只有一个网格。在里面我有一些控制。

Expected Behavior :

虽然鼠标按下发生在网格内的一个控件上,但我需要将光标更改为等待并且需要防止下一次点击直到特定时间,因此在 MouseDown 事件中我将光标设置为等待图像的 IsHitTestVisible 为假。但这没有按预期工作。

Code Block

<Grid x:Name="Grid1" Grid.Row="1" Grid.Column="1" Cursor="{Binding CurrentCursor}">
  <Canvas x:Name="canvasElement" Width="{Binding ElementName=pupilGrid, Path=ActualWidth}" Height="{Binding ElementName=pupilGrid, Path=ActualHeight}" IsManipulationEnabled="True">
    <Image x:Name="pupilSource" Width="{Binding ElementName=pupilGrid, Path=ActualWidth}" Height="{Binding ElementName=pupilGrid, Path=ActualHeight}" Source="{Binding ImageSource}"   MouseDown="Source_MouseDown" IsHitTestVisible="{Binding CanHitAxis}"/>
    <controls:Control x:Name="targetControl" Width="30" Height="30" ClipToBounds="False" Canvas.Left="0" Canvas.Top="0" VerticalAlignment="Center" HorizontalAlignment="Center"/>
  </Canvas>
</Grid>

What I am getting :

在“Source_mousedown event”中,我将当前光标设置为等待并将IsHitTestVisible设置为false。但等待光标未设置为图像。如果我从某种意义上删除了图像的 IsHitTestVisible 属性,则等待光标也会应用于图像。谁能帮我解决这个问题?

如果将 UI 元素的 IsHitTestVisible 属性 设置为 false,它将不再响应鼠标输入,也不会触发与鼠标相关的事件。 由于 IsHitTestVisible 设置为 false,鼠标无法在 window 中看到你的 UIElement。所以你的网格光标 属性 不起作用。

您可以使用 IsEnabled 属性 在特定时间阻止鼠标按下事件,而不是 IsHitTestVisible

我想这个可以解决你的问题。