当前位置:编程学习 > wap >>

高分求解 关于WebBrowser控件

做了一个demo 简单的访问URL 浏览器,但控件没任何反应
后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace WP_Brower
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();
        }

        private void BtnBrower_Click(object sender, RoutedEventArgs e)
        {
            try
            {
               
                string path = this.TBBrower.Text;
                if (!path.Contains("http://"))
                {
                    path = "http://" + path;
                }
              
                webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
            }
            catch (Exception ex)
            {
                this.TBBrower.Text = "请输入访问地址";
            }
        }

        private void webBrowser1_Loaded(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("初次加载");
        }
       
    }
}


前台XMAL代码

<phone:PhoneApplicationPage 
    x:Class="WP_Brower.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" VerticalAlignment="Top" BorderBrush="#FF7BE5B5">

    <!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel 包含应用程序的名称和页标题-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="Kimi For Brower" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="开米极速浏览器" Margin="9,-7,0,0" FontSize="35" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - 在此处放置其他内容-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBox Height="Auto" HorizontalAlignment="Left" Margin="0,6,0,0" Name="TBBrower" Text="http://www.wpdever.com" VerticalAlignment="Top" Width="Auto" />
            <Button Content="Go" Height="72" HorizontalAlignment="Right" Margin="296,6,0,0" Name="BtnBrower" VerticalAlignment="Top" Width="160" Click="BtnBrower_Click" />
            <phone:WebBrowser HorizontalAlignment="Stretch"   Name="webBrowser1" VerticalAlignment="Stretch" Margin="0,83,0,83" Height="Auto" Width="Auto" IsScriptEnabled="True" Loaded="webBrowser1_Loaded" Tag="_Blank" HorizontalContentAlignment="Center" FontFamily="Segoe WP Light">
            </phone:WebBrowser>
        </Grid>
    </Grid>
 
    <!--演示 ApplicationBar 用法的示例代码-->
   <!--" <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="按钮 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="按钮 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="菜单项 1"/>
                <shell:ApplicationBarMenuItem Text="菜单项 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>


界面效果图,和运行点击按钮后IE无任何反应,什么都不显示.找了好多资料都没找出什么问题
--------------------编程问答-------------------- 1, webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
跟一下看看uri被解析的是否正确
2,订阅webBrowser1的navigaed完成事件,看看传入值是什么。 --------------------编程问答--------------------

http://www.cyqdata.com/windowsphone/article-detail-188 --------------------编程问答--------------------
引用 1 楼  的回复:
1, webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
跟一下看看uri被解析的是否正确
2,订阅webBrowser1的navigaed完成事件,看看传入值是什么。

地址解析没问题,我看下navigated事件 --------------------编程问答--------------------
引用 1 楼  的回复:
1, webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
跟一下看看uri被解析的是否正确
2,订阅webBrowser1的navigaed完成事件,看看传入值是什么。

事件完成后传入的值也是地址栏中的地址,没问题啊。。但就是控件没任何反应什么都不显示 --------------------编程问答--------------------
引用 4 楼  的回复:
引用 1 楼 的回复:

1, webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
跟一下看看uri被解析的是否正确
2,订阅webBrowser1的navigaed完成事件,看看传入值是什么。

事件完成后传入的值也是地址栏中的地址,没问题啊。。但就是控件没任何反应什么都不显示


传入值有html源码的属性,你找找。
或者有没有错误信息?
或者换个网站试试? --------------------编程问答--------------------
引用 5 楼  的回复:
引用 4 楼  的回复:
引用 1 楼 的回复:

1, webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
跟一下看看uri被解析的是否正确
2,订阅webBrowser1的navigaed完成事件,看看传入值是什么。

事件完成后传入的值也是地址栏中的地址,没问题啊。。但就是控件没任何反应什么都不显示


传入值有……

嗯 我看看  --------------------编程问答--------------------
引用 5 楼  的回复:
引用 4 楼  的回复:
引用 1 楼 的回复:

1, webBrowser1.Navigate(new Uri(path, UriKind.Absolute));
跟一下看看uri被解析的是否正确
2,订阅webBrowser1的navigaed完成事件,看看传入值是什么。

事件完成后传入的值也是地址栏中的地址,没问题啊。。但就是控件没任何反应什么都不显示


传入值有……

没有找到HTML的源码,也没看出有什么异常,只有content显示未能计算什么的 --------------------编程问答-------------------- 乱码了?
gb2312的网页? --------------------编程问答--------------------
引用 8 楼  的回复:
乱码了?
gb2312的网页?

乱码也该有显示把。。。我这控件压根就是点后什么东西都没有看到。。就跟最初界面设计一样 --------------------编程问答-------------------- 你输入的什么网址?我试试 --------------------编程问答--------------------
引用 10 楼  的回复:
你输入的什么网址?我试试

www.wpdever.com --------------------编程问答--------------------
引用 10 楼  的回复:
你输入的什么网址?我试试

我用了LoadCompleted事件,发现e.content.Tostring()报空异常 --------------------编程问答--------------------
引用 10 楼  的回复:
你输入的什么网址?我试试

眼镜断了,我先离开会去配副眼镜,亲,帮我看看是什么问题,控件无法显示任何网站 --------------------编程问答-------------------- 你这个是wp7吗?我之前也用过wp7,发现里面的网页根本打不开,所以可能不是你代码的问题。 --------------------编程问答-------------------- --------------------编程问答--------------------
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,