GridView details template View not binding to correct ViewModel.

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

Hi,

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:

<UserControl.Resources>
        <DataTemplate x:Key="TemplateKey">
            <Views:RowDetailsView cal:Bind.Model="{Binding RowDetailsViewModelGetter}" />
        </DataTemplate>
    </UserControl.Resources>
 
and in the ParentVieModel I have defined the property as follows:
public IRowDetailsViewModel RowDetailsViewModelGetter
        {
            get
            {
                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>
                        </i:EventTrigger>
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?
thanks,
Mark
Coordinator
Jan 18, 2011 at 2:11 PM

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