WPF Alpha 阈值
WPF中有alpha阈值吗?我使用画笔#01000000,在某些计算机上,它在鼠标点击测试(用此画笔单击表面)方面是不透明的,但在其他一些计算机上,它被认为是完全透明的,并且可以通过鼠标点击。这是什么情况?
UPD1:@阿兰不。 IsHitTestVisible 属性与 alpha 点击无关。这里的边框主体在所有计算机上都是可点击的:
<Window
x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Border BorderBrush="Red" BorderThickness="20" Background="#00000000" IsHitTestVisible="True"/>
</Window>
而这里则不是(但在某些计算机上仍然可点击 - 这就是问题):
<Window
x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Border BorderBrush="Red" BorderThickness="20" Background="#01000000" IsHitTestVisible="True"/>
</Window>
IsHitTestVisible 在这两种情况下都是 True。
Is there any alpha threshold in WPF? I use brush #01000000 and on some computers it is non-transparent in regard to mouse hit testing (clicking on surface with this brush), but on some other computers it is considered as totaly transparent and mouse click-through. What is the case?
UPD1: @Alain Nope. The IsHitTestVisible property is independent of alpha click through. Here a body of the border is click throughable on all of computers:
<Window
x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Border BorderBrush="Red" BorderThickness="20" Background="#00000000" IsHitTestVisible="True"/>
</Window>
And here it is not (but still click-throughable on some computers - that is the question):
<Window
x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Border BorderBrush="Red" BorderThickness="20" Background="#01000000" IsHitTestVisible="True"/>
</Window>
IsHitTestVisible is True in both cases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的是,大卫·安森 (David Anson) 在他的博客中说道:
http://blogs.msdn.com/b/delay/archive/2011/08/18/invisible-pixels-are-just-as-clickable-as-real-pixels-tip-use- a-transparent-brush-to-make-quot-empty-quot-parts-of-a-xaml-element-respond-to-mouse-and-touch-input.aspx
你可以只需将其设置为透明即可。我一直像OP一样使用#01000000。大卫博客上的一位网友表示,“透明”对他们不起作用。我想知道这是否与OP在某些计算机上工作的#0100000问题有关,而在其他计算机上则不然。除了在不同的计算机上运行之外,也许还有一些区别?
Interestingly, David Anson says in his blog here:
http://blogs.msdn.com/b/delay/archive/2011/08/18/invisible-pixels-are-just-as-clickable-as-real-pixels-tip-use-a-transparent-brush-to-make-quot-empty-quot-parts-of-a-xaml-element-respond-to-mouse-and-touch-input.aspx
That you can just set it to Transparent. I had always used #01000000 like the OP. One of the commonets on David's blog says Transparent didn't work for them. I wonder if this is related to the OP's problem of #0100000 working on some computers and not others. Perhaps there is some difference other than just running it on different computers?
您应该使用
IsHitTestVisible
属性显式设置。You should be setting that explicitly using the
IsHitTestVisible
property.