We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind the SelectedItems property of SfDataGrid to ViewModel property?

Platform: UWP |
Control: SfDataGrid |
Published Date: January 25, 2016 |
Last Revised Date: February 16, 2016 |
Product Version: 12.1.0.43

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:

WPF

WRT

UWP

2X faster development

The ultimate UWP UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
bluestar
May 25, 2017
there is an error that " TwoWay binding target 'SelectedItems' must be a dependency property " when use x:bind . Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon