[英]XamlParseException when loading page
我在應用程序中發現了一個奇怪的問題。 當我打開其中一個頁面時,應用程序的InitializeComponent()方法將引發XamlParseException。 我該怎么做才能擺脫這個問題? 我也沒有在我的xaml代碼中發現任何明顯的錯誤。 在這里,您可以看到我的.cs和.xaml文件頁面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;
namespace app_name
{
public partial class newsummaryPage : PhoneApplicationPage
{
List<String> savingList;
List<String> projectList;
List<String> subjectsList;
IsolatedStorageSettings settings;
Boolean amISelectingProjects = true;
Boolean firstSelection = true;
String practicesummaryText;
public newsummaryPage()
{
InitializeComponent();
//Initialize settings
settings = IsolatedStorageSettings.ApplicationSettings;
}
private void nextButton_Click(object sender, RoutedEventArgs e)
{
//Load existing list into the savingList (For temporary storage)
savingList = null;
savingList = readSetting("practiceList") != null ? (List<String>)readSetting("practiceList") : new List<String>();
//Remove existing practiceList from IsolatedStorage
settings.Remove("practiceList");
//Add the new practice summary to the savingList
savingList.Add(practiceTextBox.Text.ToString());
//Save the savingList into practiceList in IsolatedStorage
settings.Add("practiceList", savingList);
//Save the summary text itself. Add "-practicesummary" to the end of the name to be able to add it without conflicts with the projectList and it's references
settings.Add(practiceTextBox.Text.ToString() + "-practicesummary", practicesummaryText);
//Save the settings
settings.Save();
MessageBox.Show("next");
}
private void newsummaryPage_Loaded(object sender, RoutedEventArgs e)
{
//Initialize the list
projectList = new List<String>();
try
{
//Load existing list
selectprojectsandsubjectsListBox.Items.Clear();
projectList.Clear();
MessageBox.Show("loaded");
projectList = readSetting("projectList") != null ? (List<String>)readSetting("projectList") : new List<String>();
selectprojectsandsubjectsListBox.ItemsSource = projectList;
}
catch (Exception)
{
//run method CurrentProjectNotEmpty();
}
}
private static object readSetting(string key)
{
return IsolatedStorageSettings.ApplicationSettings.Contains(key) ? IsolatedStorageSettings.ApplicationSettings[key] : null;
}
private void selectprojectsandsubjectsListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
}
private void selectprojectsandsubjectsListBox_Tap(object sender, System.Windows.SizeChangedEventArgs e)
{
//Select a project/subject depending on the amISelectingProjects variable
if (amISelectingProjects.Equals(true))
{
//The user is selecting a project. Get the name from the project and use it to get the subjects
var selectedItem = selectprojectsandsubjectsListBox.SelectedItem as String;
String item = selectedItem;
MessageBox.Show("select");
subjectsList = readSetting(item) != null ? (List<String>)readSetting(item) : new List<String>();
selectprojectsandsubjectsListBox = null;
selectprojectsandsubjectsListBox.ItemsSource = subjectsList;
//Set amISelectingProjects to false so that the user can select subjects next time
amISelectingProjects = false;
//Set the ListBox to multiple selection mode for selecting multiple subjects
selectprojectsandsubjectsListBox.SelectionMode = SelectionMode.Multiple;
//Tell the user what he should do next
MessageBox.Show("The subjects corresponding the the project you selected will now appear in the list. Tap on all the items you want to create a summary of and then press create when you're finished.");
}
else if (amISelectingProjects.Equals(false))
{
//The user is selecting a subject. Select multipe
if (firstSelection.Equals(true))
{
practicesummaryText = selectprojectsandsubjectsListBox.SelectedItem as String;
firstSelection = false;
}
else if (firstSelection.Equals(false))
{
//This is not the first subject that the user selects, therefore add some characters in between
practicesummaryText = practicesummaryText + ". New subject= " + selectprojectsandsubjectsListBox.SelectedItem as String;
}
}
}
}
}
我的xaml文件:
<phone:PhoneApplicationPage
x:Class="app_name.newsummaryPage"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="#FF03171B" Loaded="newsummaryPage_Loaded">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="1111"/>
<RowDefinition Height="0*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,0,0,0" Height="116" VerticalAlignment="Top">
<TextBlock Text="app name" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="New summary" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<Grid x:Name="newsummaryGrid" Margin="0,116,12,370">
<TextBox x:Name="practiceTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Width="458" Margin="0,27,0,0" Height="72" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="10,0,0,0" TextWrapping="Wrap" Text="Enter a new name for your summary:" VerticalAlignment="Top"/>
<Button x:Name="nextButton" Content="Create the summary" HorizontalAlignment="Left" Margin="0,553,0,0" VerticalAlignment="Top" Width="456" Click="nextButton_Click"/>
<ListBox x:Name="selectprojectsandsubjectsListBox" Margin="10,99,12,80" SelectionChanged="selectprojectsandsubjectsListBox_SelectionChanged" FontSize="36" Tap="selectprojectsandsubjectsListBox_Tap"/>
</Grid>
<!--ContentPanel - place additional content here-->
</Grid>
</phone:PhoneApplicationPage>
內部例外:
請參見輸出窗口,該窗口通常包含有關異常內容的有用信息。
或在出現異常窗口時,按Break鍵並轉到Visual Studio DEBUG菜單,選擇Windows-> locals。 例外應該出現在本地視圖中。
或嘗試調試並捕獲異常,而不是查看異常的屬性和內部消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.