Hi! I use RadGridView in one of the views of my WPF MVVM Prism 6 application. The view was created on the base of Prism UserControl (WPF). The
solution of my application was created as empty Telerik project. After I had created the solution I added here RadWindow as Shell and also Prism 6
library for WPF via NuGet. I want to map RadGridView.AddingNewDataItem event to a command in viewmodel but unfortunately I can't. Below is RadGridView' XAML snippet from view' markup:
<telerik:RadGridView Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" Margin="8,5,0,0" VerticalAlignment="Top" AutoGenerateColumns="False"
IsReadOnly="True" ItemsSource="{Binding DeviceRecords}" SelectedItem="{Binding SelectedDevice}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding DeviceName}" Header="Name"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding SerialNumber}" Header="Serial Number"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding MountingLocation}" Header="Mounting place"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding CompanyOwnerOfDevice}" Header="Device' owner"/>
</telerik:RadGridView.Columns>
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding
Command="{Binding HandleAddingNewRecordToDevicesGridCommand}"
EventName="AddingNewDataItem"
PassEventArgsToCommand="True"/>
</telerik:EventToCommandBehavior.EventBindings>
</telerik:RadGridView>
Below is HandleAddingNewRecordToDevicesGridCommand command that is in viewmodel:
public DelegateCommand<object> HandleAddingNewRecordToDevicesGridCommand { get; private set; }
private void handleAddingNewRecordToDevicesGrid(object parameter)
{
// Get RadGridView that is sender.
Telerik.Windows.Controls.RadGridView gridView =
((parameter as GridViewAddingNewEventArgs).OwnerGridViewItemsControl) as Telerik.Windows.Controls.RadGridView;
// Get new item inserted in the RadGridView.
Telerik.Windows.Controls.GridViewDataColumn newItem =
((parameter as GridViewAddingNewEventArgs).NewObject) as Telerik.Windows.Controls.GridViewDataColumn;
// Prepair to select this new item in the RadGridView.
Telerik.Windows.Controls.GridViewDataColumn[] aItem = { newItem };
System.Collections.IEnumerable selectedItem = aItem;
// Select the new item in the RadGridView.
gridView.Select(selectedItem);
}
this.HandleAddingNewRecordToDevicesGridCommand = new DelegateCommand<object>(this.handleAddingNewRecordToDevicesGrid); // (in viewmodel constructor)
I'm in need of abovementioned code for selecting new inserted row in the RadGridView. So after new row has been inserted into RadGridView then this row is selected in the RadGridView. But HandleAddingNewRecordToDevicesGridCommand command doesn't fire at all! Why? Please help me.