【发布时间】:2013-02-02 00:05:27
【问题描述】:
好的。这是 WPF,我正在尝试将我的窗口绑定到我的 ViewModel。虚拟机如下所示:
public class VM
{
public SalesRecord SR {get; set;}
public List<string> AllSalesTypes {get; set;}
}
public class SalesRecord
{
public int ID {get; set;}
public DateTime Date {get; set;}
}
这是我的 XAML:
...
<TextBox Text="{Binding Path=ID, Mode=TwoWay}" />
<TextBox Text="{Binding Path=Date, Mode=TwoWay}" />
<ComboBox ItemsSource="{Binding AllSalesTypes}" Text="{Binding Path=SalesType, Mode=TwoWay}" />
...
我在运行时将数据上下文设置为 VM 对象,如下所示:
this.DataContext = _vm.SR;
现在绑定表达式适用于我所有指向SR 对象属性的TextBoxes(例如ID 和Date),但ComboBox 需要显示所有SalesTypes 的列表不起作用,显然是因为AllSalesTypes 是VM 类的成员。
我的问题是:有没有办法编写一个绑定表达式来查看当前 DataContext 的父级而不是自身?
【问题讨论】:
标签: wpf mvvm binding viewmodel