2X faster development
The ultimate WPF UI toolkit to boost your development speed.
SfDataGrid.SelectedItems is a collection property. So, whenever the SelectedItems collection is changed, the property bound with SelectedItems does not get notified for this change. However, you can achieve this by creating an attached property for SelectedItems. The following is an attached property created for SfDataGrid and the property value is updated based on SfDataGrid.SelectedItems.CollectionChanged event. C# SfDataGrid’s SelectedItems values are set to the attached property by using SelectedItems.Collectionchanged event. The following is the ViewModel property bound to the attached property that you created in the above code example. XAML Now, whenever the SelectedItems collection is changed the ViewModel property gets notified via the attached property. Sample Links: |
2X faster development
The ultimate WPF UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
I tried this but the bound item does not receive the collection because it cannot convert to the target type
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=SelectedItems; DataItem='MyControlViewModel' (HashCode=38423585); target element is 'SyfDataGrid' (Name='BtcGrid'); target property is 'SelectedItems' (type 'ObservableCollection`1') ArgumentException:'System.ArgumentException: Object of type 'System.Collections.ObjectModel.ObservableCollection`1[System.Object]' cannot be converted to type 'System.Collections.ObjectModel.ObservableCollection`1[MyClass]'.
I tried this but the bound item does not receive the collection because it cannot convert to the target type
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=SelectedItems; DataItem='MyControlViewModel' (HashCode=38423585); target element is 'SyfDataGrid' (Name='BtcGrid'); target property is 'SelectedItems' (type 'ObservableCollection`1') ArgumentException:'System.ArgumentException: Object of type 'System.Collections.ObjectModel.ObservableCollection`1[System.Object]' cannot be converted to type 'System.Collections.ObjectModel.ObservableCollection`1[MyClass]'.
Also, The OnSelectedItemsChanged method is called multiple times after the first selection. This effectively renders any usage impractical.