【发布时间】:2013-05-07 19:03:08
【问题描述】:
我的 VM 具有我的模型的属性 Authorization,它的属性为 ActiveService。
public Authorization Authorization
{
get
{
return this.authorization;
}
set
{
this.authorization = value;
NotifyOfPropertyChange();
}
}
我在我的 ViewModel 上创建了一个名为 Services 的附加属性来填充下拉列表:
public IList<Service> Services
{
get { return services; }
set
{
services = value;
NotifyOfPropertyChange();
}
}
我的视图有一个名为Services 的combobox 控件。我对 Caliburn 及其约定的理解是这应该有效。但是它不能正确显示我的项目。它在列表中有正确数量的项目,但它只显示“找不到 Models.Service 的视图”
对我做错了什么有帮助吗?
编辑
所以我现在尝试的是这个;我像这样手动设置 DisplayMemberPath 绑定:
DisplayMemberPath="{Binding Authorization_ActiveService_Description}"
然后我在ToString() 上的Service 对象中添加了一个Override,如下所示:
public override string ToString()
{
return string.Format("{0}", this.Description);
}
这很有效,因为它现在在下拉菜单中显示我的描述。不过我有点困惑。我能够删除 _Description 并且它的工作原理相同。如果我删除覆盖它根本不起作用。
为什么不对我的描述属性进行深度绑定?
【问题讨论】:
-
stackoverflow.com/questions/11083314/… 这与我的问题类似,但从来没有解决方案...
-
嗯...我看不出为什么简单的
SelectedItem绑定在这里不起作用,但也许我在图片中遗漏了一些东西。 -
@Trustme-I'maDoctor 你能详细说明你的意思吗? WPF、MVVM 和 Caliburn.Micro 的新手,所以答案可能就在于我的无知。
标签: c# .net wpf mvvm caliburn.micro