Xaml 无法创建“X"的实例. [英] Xaml cannot create an instance of "X"
本文介绍了Xaml 无法创建“X"的实例.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Windows Phone 7 中为我的应用程序创建一个设置页面.我创建了 AppSettings 类并从我的 MainPage.xaml 引用它.这是我的代码:
I am trying to create a Settings page for my app in Windows Phone 7. I created the AppSettings class and is referring 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>
但是在我引用 AppSettings 的行(本地:AppSettings 行)上,我收到一条错误消息,指出无法创建 AppSettings 的实例".
But on the line where I refer the AppSettings (local:AppSettings line) , I get an error message stating that " cannot create an instance of AppSettings".
推荐答案
这是因为实例化 ApplicationsSettings 会引发异常.如果您将以下内容添加到您的构造函数中,您应该没问题;
This is because instantiating ApplicationsSettings 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
}
这篇关于Xaml 无法创建“X"的实例.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文