我有两个班级:
public class ScheduleViewModel : NotificationObject
{
private ObservableCollection<RecordingsCollection> _collection
public ObservableCollection<RecordingsCollection> Collection
{
get { return _collection; }
set
{
_collection= value;
RaisePropertyChanged(() => Collection);
}
}
}
public class RecordingsCollection : NotificationObject
{
private ObservableCollection<Recording> _recordings;
public ObservableCollection<Recording> Recordings
{
get { return _recordings; }
set
{
_recordings = value;
RaisePropertyChanged(() => Recordings);
}
}
}
在妈妈那里我只有虚拟数据
var a = new ObservableCollection<Recording>();
a.Add(new Recording()
{
Name = "Bla bla",
Schedule = new Schedule()
{
Name = "bla"
}
});
Collection.Add(new RecordingsCollection() { Recordings = a });
var b = new ObservableCollection<Recording>();
b.Add(new Recording()
{
Name = "Bla bla",
Schedule = new Schedule()
{
Name = "bla"
}
});
Collection.Add(new RecordingsCollection() { Recordings = b });
我将这一切绑定到像这样的项目控件
<ItemsControl Grid.Row="1" ItemsSource="{Binding Collection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<telerikGridView:RadGridView
ItemsSource="{Binding ElementName=RecordingDataPager, Path=PagedSource}">
<telerikGridView:RadGridView.Columns>
<telerikGridView:GridViewDataColumn Header="Schedule" DataMemberBinding="{Binding Path=Recordings.Schedule.Name}"/>
</telerikGridView:RadGridView.Columns>
</telerikGridView:RadGridView>
<telerik:RadDataPager x:Name="RecordingDataPager"
Source="{Binding RecordingsCollection, Mode=TwoWay}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
除了Recordings
中RecordingsCollection
属性的get方法之外,所有内容都被解雇(即我看到两个数据分析符,这意味着它会看到两个条目)
有什么想法吗?
修改 找到了issuse ...而不是绑定到RecordingsCollection我应该绑定录音......现在一切正常......希望这有助于将来的某个人:)
答案 0 :(得分:0)
这是答案
<ItemsControl Grid.Row="1" ItemsSource="{Binding Collection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<telerikGridView:RadGridView
ItemsSource="{Binding ElementName=RecordingDataPager, Path=PagedSource}">
<telerikGridView:RadGridView.Columns>
<telerikGridView:GridViewDataColumn Header="Schedule" DataMemberBinding="{Binding Path=Schedule.Name}"/>
</telerikGridView:RadGridView.Columns>
</telerikGridView:RadGridView>
<telerik:RadDataPager x:Name="RecordingDataPager"
Source="{Binding Recordings, Mode=TwoWay}"/>
</Grid>
</DataTemplate>