手机webbrowser.navigate没有导航到网址

时间:2013-01-08 15:43:13

标签: windows-phone-7

我正在为Windows手机做第一个教程。我已经下载了sdk和更新。我正在按照下面的教程。

tutorial

当我编译并单击调试时,模拟器将启动并正确显示UI。问题是当我点击“开始”按钮时,没有任何反应。该应用应显示上面文本框中的网址。

有没有人有任何想法,抱歉,如果它很明显但我今天开始从Android背景学习这个。

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub url_TextChanged(sender As System.Object, e As System.Windows.Controls.TextChangedEventArgs) Handles url.TextChanged

    End Sub

    Private Sub Go_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

        Dim site As String

        site = URL.Text

        MiniBrowser.Navigate(New Uri(site, UriKind.Absolute))

    End Sub
End Class

<phone:PhoneApplicationPage 
    x:Class="MiniBrowser.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">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY FIRST APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Mini Browser" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBox x:Name="URL" Margin="0,0,120,0" Text="http://www.xbox.com" VerticalAlignment="Top"/>
            <Button x:Name="Go" Content="Go" VerticalAlignment="Top" HorizontalAlignment="Right"/>
            <phone:WebBrowser x:Name="MiniBrowser" Margin="0,84,0,0"/>
        </Grid>
    </Grid>

    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>

2 个答案:

答案 0 :(得分:0)

哦,非常基本的错误:(

您忘记为Button分配Click事件处理程序

<Button x:Name="Go" Content="Go" Click="Go_Click" VerticalAlignment="Top" HorizontalAlignment="Right"/>

答案 1 :(得分:0)

我看到没有任何事情发生,虽然我有GO按钮的事件,下面是代码

XAML

        <Button x:Name="Go" Content="Go" HorizontalAlignment="Right" Margin="346,10,0,0" VerticalAlignment="Top" Click="Go_Click"/>

CS

private void Go_Click(object sender,RoutedEventArgs e)

    {
        //string site = URL.Text;
        //MiniBrowser.Navigate(new Uri(site, UriKind.Absolute));
        string site = URL.Text;
        if (String.IsNullOrEmpty(site)) return;
        if (!site.StartsWith("http://") && !site.StartsWith("https://"))
            site = "http://" + site;
        MiniBrowser.Navigate(new Uri(site, UriKind.RelativeOrAbsolute));
    }