【发布时间】:2012-02-23 07:00:40
【问题描述】:
我很难将以下结构绑定到 XAML 视图:
public class SampleViewModel : ViewModelBase
{
public ObservableCollection<ChildViewModel> Child { get; set; }
...
public ObservableCollection<Country> Countries { get; set; }
...
}
public class ChildViewModel : ViewModelBase
{
private int _CountryId;
public int CountryId
{
get { return _CountryId; }
set
{
_CountryId = value;
OnPropertyChanged("CountryId");
}
}
...
}
// Country structure is not shown, just an int and string for CountryID
// and Name in this case
SampleViewModel 的实例被设置为 View 的 DataContext。我将集合 Child 绑定到 GridView ItemsSource。在 GridView 中,我有一个 Country 组合框,我想用 SampleViewModel 中的 Country 集合填充它。
<Telerik:RadGridView ItemsSource="{ Binding Child }" ...>
<Telerik:RadGridView.Columns>
<Telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryId}"
SelectedValueMemberPath="Id"
DisplayMemberPath="Name"
ItemsSource="{Binding ????}" />
...
...
...
ItemsSource 应该是什么?如何返回 ItemsSource="{ Binding Child }" 中的根 VM 属性?
或者我应该如何重构 ViewModel 以实现上述目标?
【问题讨论】: