2016-11-25 30 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