项目控制与两个可观察集合的绑定
我有两个类:
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>
一切都很好地触发(即我看到两个数据分页器,这意味着它看到两个条目),除了 < 的 get 方法RecordingsCollection
中的 code>Recordings 属性 有什么想法吗?
编辑 找到了问题...我应该绑定到 Recordings,而不是绑定到 RecordingsCollection...现在一切正常...希望这对将来的人有帮助:)
I have a two classes:
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);
}
}
}
At the momment I have only dummy data
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 });
I bind this all to an items control like this
<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>
Everything is fired fine (i.e. i see two datapagers which means that it sees two entries) except for the get method of the Recordings
property in RecordingsCollection
Any ideas?
Edit
Found the issuse... Instead of binding to RecordingsCollection I should have bound to Recordings... Now everything works fine... Hope this helps someone in future :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是答案
This is the answers