2012-02-14 45 views
0

結合我有兩類:項的控制有兩個觀察集合

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); 
     } 
    } 
} 

在momment我只有僞數據

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> 

一切都很好(即我看到兩個數據採集器,這意味着它看到兩個條目)除g et方法Recordings財產RecordingsCollection 任何想法?

編輯 找到了issuse ......而是結合RecordingsCollection我應該綁定到錄音......現在一切正常...希望這可以幫助別人在未來:)

+0

那麼請加入您的答案,並接受它,以紀念這個問題的回答:) – 2012-02-14 10:51:15

回答

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>