0
我有约束力的后续结构XAML浏览困难: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的实例设置为视图的DataContext的。我将集合Child绑定到GridView ItemsSource。在GridView中,我有一个ComboBox for Country,我想用SampleViewModel中的Countries集合填充它。
<Telerik:RadGridView ItemsSource="{ Binding Child }" ...>
<Telerik:RadGridView.Columns>
<Telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryId}"
SelectedValueMemberPath="Id"
DisplayMemberPath="Name"
ItemsSource="{Binding ????}" />
...
...
...
什么应该是ItemsSource?我怎样才能回到根目录VM的属性在一个ItemsSource =“{Binding Child}”?
或者我应该如何重构ViewModel才能达到上述目的?
在我的示例的XAML中修复了我的愚蠢错字之后,ElementName方法起作用。谢谢。 – Lepton 2012-02-23 08:44:17