如何将图像放在 Web 浏览器控件上 [英] How to put an image on web browser control

查看:25
本文介绍了如何将图像放在 Web 浏览器控件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在适用于 Windows Phone 7 的网络浏览器应用程序中,我在网格上创建了​​一个网络浏览器控件(在 xaml.cs 中).之后我在网格上创建了​​一个图像.但是当我在模拟器中打开网络浏览器时,该图像不可见.这是一个标签式浏览器.但图像在网格中可见但在网络浏览器控件上不可见(调试应用程序后).就像UC浏览器有这个东西.请看下面的图片,在网格上,图片是可见的,但在网络浏览器控件上,图片是不可见的.

In the web browser app for windows phone 7,i have created a web browser control(in xaml.cs) on the Grid. After that i have created an image on the Grid. But when i open the web browser in emulator, that image is not visible. It's a tabbed browser. But the image is visible in the grid but not visible on web browser control(After debugging the app). Like the UC Browser has this thing. PLease the below images, on the grid, the image is visible but on the web browser control, the image is not visible.


在 .xaml 中

    <Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBox x:Name="UrlTextBox" Background="White" InputScope="URL" KeyDown="UrlTextBox_KeyDown" Margin="0,0,98,0" GotFocus="UrlTextBox_GotFocus" LostFocus="UrlTextBox_LostFocus" KeyUp="UrlTextBox_KeyUp"/>
    <Grid x:Name="BrowserHost" 
      Grid.Row="1" GotFocus="BrowserHost_GotFocus">
        <Image x:Name="Full" Source="Images/full.png" Height="60" Width="60" Margin="430,678,0,0" MouseEnter="Full_MouseEnter" Visibility="Visible" />
    </Grid>

在 Xaml.cs 中

private void ShowTab(int index) 
{ 
    this.currentIndex = index;       
    UrlTextBox.Text = this.urls[this.currentIndex] ?? "Search"; 
    if (this.browsers[this.currentIndex] == null) 
    { 
        WebBrowser browser = new WebBrowser(); 
        this.browsers[this.currentIndex] = browser; 
        BrowserHost.Children.Add(browser); 
        browser.IsScriptEnabled = true; 
    } 
    for (int i = 0; i < NumTabs; i++) 
    { 
        if (this.browsers[i] != null) 
        { 
            this.browsers[i].Visibility = i == this.currentIndex ? Visibility.Visible : Visibility.Collapsed; 
        } 
    } 
} 

我需要在我的 Web 浏览器控件中使用该图像.有人可以帮我吗?

I need that image in my web browser control. Can anybody help me?

预先感谢您的辛勤工作!

Thanks in advance for your hard work!

推荐答案

当您在代码中添加浏览器控件时,您是将它放在图像的顶部.您需要 Grid 中的一个容器来保存您的控件.不过,最终,您可能应该尝试按照上面 Matt Lacey 所示的方式在 XAML 中进行设置.

WHen you are adding the browser control in code, you are putting it on top of the image. You need a container within the Grid to hold your controls. Ultimately, though, you should probably try to set this up in XAML the way Matt Lacey shows above.

如果你想试试这个你的方式,你需要这样的东西:

If you want do try this your way, you need something like this:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBox x:Name="UrlTextBox" Background="White" InputScope="URL" KeyDown="UrlTextBox_KeyDown" Margin="0,0,98,0" GotFocus="UrlTextBox_GotFocus" LostFocus="UrlTextBox_LostFocus" KeyUp="UrlTextBox_KeyUp"/>
    <Grid x:Name="BrowserHost" 
  Grid.Row="1" GotFocus="BrowserHost_GotFocus">
        <Grid x:Name="BrowserHolder"/>
        <Image x:Name="Full" Source="Images/Full.png" Height="60" Width="60" Margin="430,678,0,0" MouseEnter="Full_MouseEnter" Visibility="Visible" />
    </Grid>
</Grid>

注意添加了网格BrowserHolder".由于该控件是先添加的,因此您添加到该控件的任何内容都应该出现在图像后面.

Notice the addition of the Grid "BrowserHolder". Since that one was added first, anything that you add to that control should appear behind the image.

所以你的代码变成了:

private void ShowTab(int index) 
{ 
    this.currentIndex = index;       
    UrlTextBox.Text = this.urls[this.currentIndex] ?? "Search"; 
    if (this.browsers[this.currentIndex] == null) 
    { 
        WebBrowser browser = new WebBrowser(); 
        this.browsers[this.currentIndex] = browser; 

        // NOTE: Changed to BrowserHolder
        BrowserHolder.Children.Add(browser); 

        browser.IsScriptEnabled = true; 
    } 
    for (int i = 0; i < NumTabs; i++) 
    { 
        if (this.browsers[i] != null) 
        { 
            this.browsers[i].Visibility = i == this.currentIndex ? Visibility.Visible : Visibility.Collapsed; 
        } 
    } 
} 

这篇关于如何将图像放在 Web 浏览器控件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆