I have a WPF user control that contains a telerik RadGridView. The control's data context is being set to an instance of MyViewModel class. The MyViewModel class has a myRecords property, of type ObservableCollection. The RadGridView is bound thus:
ItemsSource="{Binding myRecords}"
In the RadGridView I define a number of columns, which contain DataTemplates that bind to properties of MyRecords. This is working fine.
I've added a column that contains a delete button. Or rather, that contains a DataTemplate that contains a button labeled "delete". This is bound to a command defined on the record:
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Button
Command="{Binding deleteCommand}"
CommandParameter="{Binding}">
<Label>Delete</Label>
</Button>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
And this works fine. The ICommand property I've defined on MyRecord executes.
But here's the thing - that's not where I want this code. I don't want to run a method on MyRecord, I want to run a method on MyViewModel, passing the appropriate MyRecord as an argument. The CommandParameter="{Binding}" element, above, passes the appropriate MyRecord, so that part is fine. But I've not been able to figure out how to bind the button's command to an ICommand on the MyViewModel object, instead of on the MyRecord.
I've been playing around with RelativeSource and AncestorType, and gotten nowhere.
Help would be appreciated.