This is a migrated thread and some comments may be shown as answers.

Parent Control DataContext from a Column's Celltemplate

2 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
anoop c
Top achievements
Rank 1
anoop c asked on 30 Apr 2010, 04:25 PM
Hi,

 I have placed a html button on one of the columns in the grid (gridview1).  I have set a viewModel  Items as itemsource for the grid.  I have a command defined in the view model called  Projects which holds the items viewmodel also. Because the itemsource for the grid is set as Items, the column cell templates and controls inside it only have access to Items. I need access to Projects ViewModel. 

I was able to use the DataContext={Bindng DataContext ElementName ="gridview1" } to get the Project viewmodel in my group header templates but it is coming as null when used inside the column templates.

Anybody have done this before?  I know in WPF we have findancestor etc but in Silverlight 3 what are my options?

Thanks
Anoop

2 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 04 May 2010, 02:05 PM
Hello anoop c,

From within the cells you can access either the default datacontext which as you have found is the Item  or use a static resource for the binding source.

If you place your ViewModel in the resources ( e.g. Page.Resources)  , you may access it with syntax like :  Binding Path=Projects, Source = {StaticResource MyViewModelKey}.

Kind regards,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
anoop c
Top achievements
Rank 1
answered on 04 May 2010, 02:37 PM

Thanks Pavalov,

    But I might not be able to use the static resource approach as I am using Prism and maintaining the viewmodels in my container and dynamically injecting them.

It seems I will now have to pollute my ItemsView with commanding code which otherwise was only a data collection wrapper .
Actually wanted to know if it was my ignorance or was it a true limitation.

Regards
Anoop

Tags
GridView
Asked by
anoop c
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
anoop c
Top achievements
Rank 1
Share this question
or