seb*_*aub 8 .net c# wpf hittest
在使用VisualTreeHelper.HitTest甚至隐藏元素的WPF 中找到.要跳过这些元素并仅返回可见的结果,我创建了HitTestFilter如下内容:
///This Filter should cut all invisible or not HitTest Enabled Elements
private static HitTestFilterBehavior MyHitTestFilter(DependencyObject target)
{
var uiElement = target as UIElement;
if (uiElement != null){
if(!uiElement.IsHitTestVisible || !uiElement.IsVisible))
return HitTestFilterBehavior.ContinueSkipSelfAndChildren;
}
return HitTestFilterBehavior.Continue;
}
Run Code Online (Sandbox Code Playgroud)
这个过滤器完成了他的工作,但我想知道默认的WPF HitTesting在这种情况下做了什么?它是否使用类似的过滤器?这样做还有其他更好的选择吗?
澄清一个简短的描述:

在图像中有
如果我有这样的布局并在Button2的绿色区域中执行鼠标点击,WPF会跳过Button2并且Button1上会出现click事件.
如果我在没有前面描述的过滤器的情况下进行手动HitTesting,我将得到Button2作为结果.
所以问题是,WPF使用的默认行为/过滤器是什么?
在此先感谢您的任何建议.
我知道这是一个相当老的问题,但我最近遇到了类似的问题,并通过使用UIElement.InputHitTest方法使其工作。
我换了
HitTestResult hitTest = VisualTreeHelper.HitTest(rootVisual, point);
IInputElement source = hitTest?.VisualHit as IInputElement;
Run Code Online (Sandbox Code Playgroud)
和
IInputElement source = rootVisual.InputHitTest(point);
Run Code Online (Sandbox Code Playgroud)
第二个版本跳过不可见的元素(而第一个没有)。
| 归档时间: |
|
| 查看次数: |
1221 次 |
| 最近记录: |