2016-11-25 29 views
0

我想在网页视图的一部分,与此类似应用的半透明“玻璃”层:UWP web视图与“玻璃”层不接收指针/触摸事件

screenshot

XAML :

<Page 
    x:Class="Sample.BlankPage1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid> 
     <WebView 
      Source="http://news.google.com" 
     /> 

     <Rectangle 
      Fill="Red" 
      Opacity="0.25" 
      IsHitTestVisible="False" 
      MaxWidth="200" 
     /> 

    </Grid> 
</Page> 

代码隐藏:

using Windows.UI.Xaml.Controls; 

namespace Sample 
{ 
    public sealed partial class BlankPage1 : Page 
    { 
     public BlankPage1() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

的问题是,鼠标悬停在红色矩形上时,鼠标指针是一个箭头(当悬停在超链接上时),并且点击/单击对WebView没有影响。它看起来像“IsHitTestVisible = False”实际上不工作,并且WebView没有接收事件。

我发现了一个解释命中测试的文档(https://msdn.microsoft.com/library/windows/apps/hh758286#hit_testing),它说“WebView控件具有特殊的命中测试行为” - 但仍然看起来我的示例应该起作用。

的问题是:

  1. 是当前的行为的错误吗?
  2. 是否有解决方法?

谢谢。

回答

0

当前行为是一个错误吗?

不,这不是一个错误。这是因为XAML中声明的最后一个元素是顶部绘制的元素。在您的代码片段中,Rectangle呈现在WebView控件的顶部。当指向Rectangle时,它不能得到WebView控制的重点。它与IsHitTestVisible属性没有关系。

是否有解决方法?

我改变所呈现的顺序WebViewRectangle,并设置Opacity属性代替Rectangle“web视图”,其可具有类似的效果。

<Rectangle 
     MaxWidth="200" 
     Fill="Red" /> 
    <WebView Source="http://news.google.com" Opacity="0.75"/> 

而结果:

enter image description here