how to remove XamlParseException in windows phone 8?

267 Views Asked by At

When I run my app in windows phone 8 emulator, I am getting this Exception thrown after which I can't run my app.

MainPage.xaml

<phone:PhoneApplicationPage
x:Class="LightBrowser.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"
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 Text="Light Browser" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Button x:Name="Go" Content="Go" HorizontalAlignment="Right" Margin="0,27,0,0" VerticalAlignment="Top" Click="Button_Click_1" Width="79"/>
        <phone:WebBrowser x:Name="Light_Browser" Margin="0,99,0,0"/>
        <Button x:Name="Back" Content="Back" HorizontalAlignment="Right" Margin="343,-24,0,0" VerticalAlignment="Top" Height="65" Click="Back_Click"/>
        <Button x:Name="Refresh" Content="Refresh" Margin="170,-24,159,0" VerticalAlignment="Top" Height="65" Click="Back_Click" HorizontalAlignment="Center"/>
        <TextBox x:Name="URL" Margin="0,27,68,0" VerticalAlignment="Top" Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" TextOptions.TextHintingMode="Animated" AcceptsReturn="True" Text="http://www.google.co.in/"/>
        <Button x:Name="Home" Content="Home" HorizontalAlignment="Left" Margin="3,-23,0,0" VerticalAlignment="Top" Click="Home_Click" Height="67" Width="110"/>
    </Grid>
</Grid>
</phone:PhoneApplicationPage>

MainPage.xaml.cs

namespace LightBrowser
{
public partial class MainPage : PhoneApplicationPage
{
    private Stack<Uri> _history = new Stack<Uri>();
    private string home = "http://www.google.co.in/";
    private Uri _current = null;

    // Constructor
    public MainPage()
    {
        InitializeComponent();
        Light_Browser.Navigate(new Uri("http://www.google.co.in/", UriKind.Absolute));
        Light_Browser.IsScriptEnabled = true;

    }

    private void Button_Click_1(object sender, NavigatingEventArgs e)
    {
        Uri url = e.Uri;
        URL.Text = url.ToString();
        string site = URL.Text;
        Light_Browser.Navigate(new Uri(site, UriKind.Absolute));

    }

    private void Home_Click(object sender, NavigatingEventArgs e)
    {
        Light_Browser.Navigate(new Uri(home, UriKind.Absolute));
        Uri url = e.Uri;
        URL.Text = url.ToString();
    }

    private void Back_Click(object sender, NavigatingEventArgs e)
    {
        Light_Browser.GoBack();
        Uri url = e.Uri;
        URL.Text = url.ToString();
    }

    private void Refresh_Click(object sender, NavigatingEventArgs e)
    {
        Uri url = e.Uri;
        URL.Text = url.ToString();
        string site=URL.Text; 
        Light_Browser.Navigate(new Uri(site, UriKind.RelativeOrAbsolute));
    }

    private void Browser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
    {
        MessageBox.Show("Navigation to this page failed, check your internet connection");
    }


    private async void Browser_Navigated(object sender, NavigationEventArgs e)
    {
        // If we navigated back, pop the last entry
        if (_history.Count > 0 && _history.Peek() == e.Uri)
        {
            _history.Pop();
        }
        // Otherwise, if this isn't the first navigation, push the current
        else if (_current != null)
        {
            _history.Push(_current);
        }

        // The current page is now the one we've navigated to
        _current = e.Uri;
    }

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) {
        base.OnBackKeyPress(e);

        if (_history.Count == 0)
        {
            // No history, allow the back button
            // Or do whatever you need to do, like navigate the application page
            return;
        }
        // Otherwise, if this isn't the first navigation, push the current
        else
            Light_Browser.GoBack();
    }
}
}

XamlParseException Occured

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll

And this error points to InitializeComponent();

0

There are 0 best solutions below