2014-01-05 4 views
0

내 앱에서 이상한 문제가 발견되었습니다. 페이지 중 하나를 열면 응용 프로그램의 InitializeComponent() 메서드가 XamlParseException을 throw합니다. 이 문제를 해결하려면 어떻게해야합니까? 내 xaml 코드에서 명백한 오류를 발견하지 못했습니다.XamlParseException 페이지로드 중

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> 

내부 예외 :

  • $ 예외 {System.Windows.Markup 여기 내 .cs 및 페이지 .xaml 파일을 볼 수 있습니다 .XamlParseException : 'System.Windows.UIElement.Tap'속성에 할당하지 못했습니다. System.Windows.Application.LoadComponent (Object 구성 요소, Uri resourceLocator)에서 (Knowledge_Organizer.newsummaryPage.InitializeComponent()) (Knowledge_Organizer.newsummaryPage..ctor()) System.Exception {System : Windows.Markup.XamlParseException}
+0

체크 내부 예외. –

+0

내부 예외 메시지는 어떻게 확인합니까? – Erik

+0

예외 대화 상자에서,'View Details' 하이퍼 링크가 보일 것입니다. 팝업이 열리고 내부 예외 속성이 표시됩니다. –

답변

1

일반적으로 예외 내용에 대한 유용한 정보가 포함 된 출력 창을 참조하십시오.

또는 예외 창이 나타나면 break를 누르고 Visual Studio 디버그 메뉴로 가서 windows-> locals를 선택하십시오. 예외가 지역보기에 나타나야합니다.

또는 디버그하고 예외를 잡으려고하면 속성 및 내부 메시지가 표시됩니다. 실제 예외 메시지

enter image description here enter image description here

+0

은 로컬 항목을 추가 한 것으로 보입니다. 탭 속성을 할당하고 싶지 않습니다. – Erik

+0

Managed는 실제로 그 창으로 직접 오류를 수정합니다. 약간의 실험을했는데 코드 복사 및 탭 이벤트 이름 변경 및 다시 작성으로 끝났습니다. 이제 완벽하게 작동합니다! 감사! – Erik

+0

아주 좋은 답변과 도움이 필요합니다! – Erik

관련 문제