I have a RadGridView from which I have set up an EventTrigger using the MVVMLight EventToCommand object in order to trap the SelectionChanged event in my ViewModel. This works fine when I pass in the DataGrid as an object to the ViewModel. Below is my Trigger:
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"SelectionChanged"
>
<
cmd:EventToCommand
CommandParameter
=
"{Binding ElementName=RadGrid}"
Command
=
"{Binding SelectPriotityCommand}"
PassEventArgsToCommand
=
"False"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
However when I use this pattern I then have to derive the object I am interested in from the SelectedCells collection of the Grid. Also I would rather not access the RadGridView from the ViewModel at all as this is difficult to Unit test. Therefore I would prefer to get a handle on the selected item in the collection from XAML. Should be simple! However if I substitute the CommandParemeter above with the following:
Binding ElementName='RadGrid', Path='SelectedCells[0].Item'}
Then I get the error
System.Windows.Data Error: Failed to connect to index '0' in object 'Telerik.Windows.Controls.GridView.Selection.CellInfoCollection' (type 'Telerik.Windows.Controls.GridView.Selection.CellInfoCollection'). BindingExpression: Path='SelectedCells[0].Item'
This seems to happen as soon as the page is loaded, am I simply getting this error as the collection is empty? How do I get this to work? I feel I must be missing something rather simple?
Regards,
Andy