我正在使用Visual Studio Express 2012 for Windows Phone制作Windows Phone 7.1应用。
我在MainPage.xaml中添加了这个命名空间:
xmlns:myNameSpace="clr-namespace:MyApp"
And this:
<Grid.Resources>
<myNameSpace:MyClass x:Key="referenceToMyClass" />
</Grid.Resources>
在同一个文件中使用如下:
<ListBox Name="MyListBox"
Height="{Binding ElementName=ContentPanel, Path=Height}"
Width="{Binding ElementName=ContentPanel, Path=Width}"
ItemsSource="{StaticResource referenceToMyClass}"
DisplayMemberPath="MyAttribute" />
我的类看起来像这样:
namespace MyApp
{
class MyClass : ObservableCollection<AnotherClass>
{
public MyClass()
{
Class temp = new AnotherClass("Example attribute");
Add(temp);
}
public void AddAnotherClass(AnotherClass anotherClass)
{
Add(anotherClass);
}
}
}
当我尝试在我的手机上进行调试时,我遇到了以下错误:
在System.Windows.dll中发生了类型为'System.Windows.Markup.XamlParseException'的第一次机会异常 其他信息: 在类型'MyApp.MyClass'上找不到匹配的构造函数。