1

我正在为 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......它绕过我的示例数据文件,但仅适用于这个自定义对象。

4

2 回答 2

1

尝试这个:

<local:MainViewModel 
    xmlns:local="clr-namespace:Project.ViewModels"
    TestProperty ="I'm the Design testProperty and I work"
    xmlns:local2="clr-namespace:Project.NamespaceDefinitionOfTheCustomClass">

    <local:MainViewModel.Custom>
        <local2:Custom Title="Hey, i'm the Design Custom, and I don't work" />
    </local:MainViewModel.Custom>

</local:MainViewModel>

如果你的类“Custom”没有在类“MainViewModel”的同一个命名空间中定义,那么像我一样添加命名空间声明,否则只删除它并将local2范围重命名为local;

这个对我有用。希望这对你有用。

于 2012-05-26T21:21:08.750 回答
0

尝试稍微简单的:

<local:MainViewModel 
    xmlns:local="clr-namespace:Project.ViewModels"
    TestProperty ="I'm the Design testProperty and I work">

    <local:Custom Title="Hey, i'm the Design Custom, and I don't work" />
</local:MainViewModel>
于 2012-05-04T12:35:56.790 回答