如何将WebBrowser控件放在其他控件下面?

时间:2011-06-27 11:34:24

标签: silverlight silverlight-4.0

我尝试设置Canvas.ZIndex属性,但是当我滚动时,webBrowser控件中的HTML仍然浮动在Silverlight导航应用程序的菜单栏上方。

您可以在下面看到示例代码:

我刚刚创建了一个空的Silverlight导航应用程序,并在Home.XAML中添加了以下内容:

<navigation:Page x:Class="Test.Home" 
    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"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    Title="Home"
    Style="{StaticResource PageStyle}" Canvas.ZIndex="1">

    <Grid x:Name="LayoutRoot">
        <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">

            <StackPanel x:Name="ContentStackPanel">

                <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" 
                                   Text="Home Content"/>
                <TextBlock x:Name="lblInstructions" Style="{StaticResource ContentTextStyle}" 
                                   Text="Instructions "/>
                <WebBrowser Name="HTMLContent" Height="850" Width="600" Canvas.ZIndex="0" />
                <TextBlock x:Name="lblScribble" Style="{StaticResource ContentTextStyle}" 
                                   Text="Scribble here "/>
                <InkPresenter Name="inkPresenter1" DataContext="{Binding}" Cursor="Stylus" Opacity="1" />
            </StackPanel>

        </ScrollViewer>
    </Grid>

然后在代码中设置HTML内容:

HTMLContent.NavigateToString("<p>Some HTML</p>");

当我向下滚动时,HTML内容会超出顶部的导航。这告诉我webBrowser控件高于其他控件。但是设置Canvas.ZIndex并没有做任何事情。

1 个答案:

答案 0 :(得分:2)

这是一个常见的“airspace issue”,类似于WPF airspace issue。目前没有办法让它出现在您的其他Silverlight内容之后。

(对于第一个链接搜索“空域”以查找相关信息)。