Frage

I've found a weird problem in my app. When I open one of the pages, the app's InitializeComponent() method throws an XamlParseException. What can I do to get rid of this issue? I haven't found any obvious errors in my xaml code either. Here you can see my .cs and .xaml file of the page:

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;
            }
        }
    }
}
}

My xaml file:

<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>

Inner exception:

  • $exception {System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.UIElement.Tap'. [Line: 32 Position: 172] at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at Knowledge_Organizer.newsummaryPage.InitializeComponent() at Knowledge_Organizer.newsummaryPage..ctor()} System.Exception {System.Windows.Markup.XamlParseException}
War es hilfreich?

Lösung

See the output window, it usualy contains useful information about the exception's content. enter image description here

or when the exception window appears, press break and go to visual studio DEBUG menu, choose windows->locals. the exception should appear in the locals view.

or try to debug and catch the exception, than see it's properties and inner message.

enter image description here enter image description here

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top