Xaml cannot create an instance of "X"

I am trying to create a settings page for my application in Windows Phone 7. I created the AppSettings class and reference it from my MainPage.xaml. This is my code:

<phone:PhoneApplicationPage 
    x:Class="Shapes4Kids.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"
    xmlns:local="clr-namespace:ShapesSettings;assembly=Shapes4Kids" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.Resources>
        <local:AppSettings x:Key="appSettings"></local:AppSettings>
    </phone:PhoneApplicationPage.Resources>

But in the line where I refer to the line AppSettings (local: AppSettings), the error message "Unable to instantiate AppSettings" appears.

+5
source share
3 answers

This is because instantiating ApplicationSettings throws an exception. If you add the following to your constructor, you should be fine,

try
{
    settings = IsolatedStorageSettings.ApplicationSettings;
}
catch (System.IO.IsolatedStorage.IsolatedStorageException e)
{
    // handle exception
}
+4
source

, ​​xaml, , . , .

, .

+3

.

, XAML:

public static readonly DependencyProperty ListViewObjectProperty = DependencyProperty.Register(
                                                                                                "ListViewObject",
                                                                                                typeof(ListView),
                                                                                                typeof(WidthConverter),
                                                                                                new UIPropertyMetadata(0));

... ListView. "propdp" VS " UIPropertyMetadata (0)", . " UIPropertyMetadata (null)".

Change this fixed for me. For some reason, I am not getting this apparent exception at runtime.

0
source

All Articles