【问题标题】:Setting IsHitTestVisible to false affects the cursor in wpf将 IsHitTestVisible 设置为 false 会影响 wpf 中的光标
【发布时间】:2017-12-07 06:46:46
【问题描述】:

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

预期行为:

当鼠标按下网格内的一个控件时,我需要将光标更改为等待,并且需要防止下一次点击直到特定时间,所以在MouseDown 事件中,我将光标设置为等待和@987654322图像的@ 为假。但这并没有按预期工作。

代码块

<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>

我得到了什么:

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

【问题讨论】:

    标签: c# wpf cursor


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-08-22
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多