In other words, the parent view has an embedded (first-level) child view. This child view contains another (2nd-level) child view embedded into it. The 2nd-level child view has a RadGridView which is bound to an observable collection. You can Add/Edit/Delete rows in the gridview.
How can I gain access to this obs. collection from the parent view, which needs the updated rows from the radgridview.
I was assuming, that I need to expose a dependancy property from within the child (1st or 2nd level ???? not sure) which could help me to gain access to that collection. Can you point me to any best practice in SL4 and MVVM.
Thanks.
HDD.
3 Answers, 1 is accepted
I believe at data level you could subscribe to the Collection changed events of the Observable collection.
Additionally if you need to track changes of the properties within the item - your business objects should implement the INotifyPropertyChanged interface . This way you will be able to subscribe to these changes and perform the right actions.
In the context of MVVM this should not happen at the UI layer.
These are just general thoughts. If you can give me some more details on what kind of changes exactly do you need to track and what action do you need to take on these changes, I can be more specific .
Regards,
Pavel Pavlov
the Telerik team
http://www.telerik.com/community/forums/silverlight/gridview/add-a-new-row-to-the-parent-gridview-from-a-child-popup-form.aspx
Essentially, I am reusing this code and have expanded one level deep. So now my view structure varies somewhat like this.
Parent View ---->
----> Embeds a Child View (Level 1). [This view embeds a couple more views]
---> Embeds a Child View A (level 2)
---->Embeds other child views and controls (level 2)
Now the Child View A at level 2 has a RadGridView, displaying a list of players (with Add/Delete/Edit row featrues) and is bound to the "Players" observable collection as below:
<telerik:RadGridView Name="playersGrid"
ItemsSource="{Binding Players}" SelectedItem="{Binding SelectedItem}" AutoGenerateColumns="False" telerikControls:StyleManager.Theme="Windows7">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/>
<telerik:GridViewColumn Header="Delete">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton
Command="{Binding DeletePlayerCommand, Source={StaticResource MyViewModel}}"
CommandParameter="{Binding}"
Content="Delete"/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
<telerik:GridViewColumn Header="Info" >
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton
Command="{Binding InfoCommand, Source={StaticResource MyViewModel}}"
CommandParameter="{Binding}"
Content="Info" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Now, I am trying to gain access to this "Players" obs collection in my Parent View Model to get the count of Players and pass the collection to another view for processing.Hope this should make more sense now.
Thanks.
May I see the code of your parent view model .
I believe It should contain references to the objects with the Players property ,and this should allow you to get access to the players collection or maybe I am missing something ?
Since the Players is an observable collection , changes made as result of add/delete operations should be easily trackable.
One more tought - the parent RadGridView hasselected item property , so having this , you may easily get access to the current item and its players respectively . Something Like :
ParentGridView.SelectedItem.Players -> of course here you will need to cast the SelectedItem to the type of the object with the Players property,
As an alternative, to avoid further confusion, you may send me the project , describe the desired behavior
and let me implement it for you .
Regards,
Pavel Pavlov
the Telerik team