当我在 windows phone 8 模拟器中运行我的应用程序时,我收到了这个异常,之后我无法运行我的应用程序。
主页.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
System.Windows.ni.dll 中出现“System.Windows.Markup.XamlParseException”类型的第一次机会异常
这个错误指向InitializeComponent();