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. Image for the cookie policy date
close icon

Binding to SelectedItems property

Hello,

Q: What is a proper way to bind SfDiagram.SelectedItems property to ViewModel's corresponding property?
Tried the following:

XAML:

<sf:SfDiagram.SelectedItems>
    <sf:Selector DataContext="{Binding SelectedItems}"/>
</sf:SfDiagram.SelectedItems>

(assuming that DataContext is a VM object)

In VM:

private SelectorViewModel selectedItems = new SelectorViewModel() {
Nodes = new ObservableCollection<NodeViewModel>(),
Connectors = new ObservableCollection<ConnectorViewModel>();
};
public SelectorViewModel SelectedItems {
get { return selectedItems; }
set {
selectedItems = value;
OnPropertyChanged(nameof(SelectedItems));
}
}

but getting an Exception after trying to select something (even the diagram itself).

3 Replies

RA Ranjitha Amirthalingam Syncfusion Team December 1, 2016 09:33 AM UTC

Hi Artemy, 
 
Thanks for Contacting Syncfusion Support. 
 
Requirement: To bind the custom ViewModel for Selected Items. 
 
The SelectedItems property of SfDiagram is type of SelectorViewModel which is the default DataContext of Selector. We assumed that your requirement is to bind the SelectorViewModel (from ViewModel class) to SelectedItems property of SfDiagram. We have represented this in simple sample. Please refer to that as below. 
 
 
Sample Details: 
We have created ViewModel (named as “DiagramVM”) for Diagram with Custom property for SelectedItems. 
  
Regards, 
Ranjitha A. 



AR Artemy December 6, 2016 11:31 AM UTC

Thank you 


KR Keerthivasan Ramamoorthy Syncfusion Team December 8, 2016 04:47 AM UTC

Hi Artemy,  
Thanks for the update.  
Please let us know if you need any other assistance.   
   
Regards,   
Keerthivasan R.   


Loader.
Live Chat Icon For mobile
Up arrow icon