【发布时间】:2012-05-03 13:53:46
【问题描述】:
我正在为 Windows Phone 7.0 开发一个应用程序,并且我正在尝试添加一个示例设计数据文件,以便在我使用 Visual Studio 时获得一些图形。 String 或 int 类型可以正常工作,但自定义对象不行。
我解释一下:
我有一个这样的类:(代表我的自定义对象)
public class CustomObject
{
public string Title { get; set; }
}
这是我的视图模型:
public class MainViewModel
{
public MainViewModel()
{
this.Custom= new CustomObject();
this.Custom.Title = "Hey, i'm the Runtime Custom";
}
public CustomObject Custom{ get; set; }
public string TestProperty { get; set; }
}
我已经创建了一个这样的示例数据文件:
<local:MainViewModel
xmlns:local="clr-namespace:Project.ViewModels"
TestProperty ="I'm the Design testProperty and I work">
<local:MainViewModel.Custom Title="Hey, i'm the Design Custom, and I don't work" />
</local:MainViewModel>
在我的应用程序的主页中,我在电话标签中添加了这个:
d:DataContext="{d:DesignData SampleData.xaml}"
好吧,当我使用这样的 TestProperty 变量 (Text="{Binding TestProperty}") 进行测试时,它可以正常工作,但是当我尝试使用这样的对象 (Text="{Binding Custom.Title}") 时,它就不起作用了...
我找到的所有资源都不能谈论自定义对象。
有人知道吗?
坦克。
PS:我尝试添加 DesignData 标签(最能描述我的问题)但我不允许:(
编辑:
没有编译,Visual Studio 不显示任何内容,当我编译时,它显示 Hey, i'm the Runtime Custom... 它绕过了我的示例数据文件,但仅针对此自定义对象。
【问题讨论】:
标签: windows-phone-7 xaml data-binding