GridView details template View not binding to correct ViewModel.

Jan 18, 2011 at 1:07 PM
Edited Jan 18, 2011 at 1:08 PM


I'm having a problem getting the ViewModelBinder to bind the correct ViewModel to a DataTemplate view. 

In the ParentView  I'm setting up the DataTemplate as follows:

        <DataTemplate x:Key="TemplateKey">
            <Views:RowDetailsView cal:Bind.Model="{Binding RowDetailsViewModelGetter}" />
and in the ParentVieModel I have defined the property as follows:
public IRowDetailsViewModel RowDetailsViewModelGetter
                return this.rowDetailsViewModel;
I have set the grid up like this:
<telerik_gridview:RadGridView  AutoGenerateColumns="False" RowDetailsTemplate="{StaticResource TemplateKey}">
When I expand a parent row the RowDetailsView is shown correctly. However, there is an Add button on the RowDetails view which I want to be bound to RowDetailsViewModel.Add(). The button is configured with an ActionMessage as follows:
<i:EventTrigger EventName="Click">
                            <cal:ActionMessage MethodName="Add"></cal:ActionMessage>
The problem is that the framework wants to bind the Add ActionMessage to ParentViewModel.Add() instead of RowDetailsViewModel.Add() (I figured this out after lots of playing around!)
Is the framework capable of doing what I want? If so what is it that I am doing wrong?
Jan 18, 2011 at 3:11 PM

Inside of your row template, try adding an Action.Target="{Binding}" to the root element.