Back to Devexpress

SankeyDiagramControl.SelectedItems Property

wpf-devexpress-dot-xpf-dot-charts-dot-sankey-dot-sankeydiagramcontrol-781a3f71.md

latest10.1 KB
Original Source

SankeyDiagramControl.SelectedItems Property

Gets or sets the collection of selected Sankey links and nodes.

Namespace : DevExpress.Xpf.Charts.Sankey

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
[NonCategorized]
public IList SelectedItems { get; set; }
vb
<NonCategorized>
Public Property SelectedItems As IList

Property Value

TypeDescription
IList

The collection of selected Sankey links and nodes.

|

Remarks

Add links and nodes to the SelectedItems collection to select them. When you use the SelectedItems property to change the Sankey element selection, the SankeyDiagramControl ignores whether the selection is enabled in the SelectionMode property.

The following example selects the France node and the related links:

xaml
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        xmlns:dxsa="http://schemas.devexpress.com/winfx/2008/xaml/sankey" 
        x:Class="WpfApp1.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow">

    <Grid>
        <dxsa:SankeyDiagramControl x:Name="sankeyDiagramControl1" 
                                   DataSource="{Binding Data}" 
                                   SelectedItems="{Binding SelectedSankeyItems}"
                                   SourceDataMember="Source" 
                                   TargetDataMember="Target" 
                                   WeightDataMember="Value">
            <!--...-->
            <dxsa:SankeyDiagramControl.DataContext>
                <local:SankeyViewModel/>
            </dxsa:SankeyDiagramControl.DataContext>
        </dxsa:SankeyDiagramControl>
    </Grid>
</Window>
csharp
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows;
using DevExpress.Xpf.Charts.Sankey;

namespace WpfApp1 {

    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
    }

    public class SankeyViewModel : INotifyPropertyChanged {
        IList<object> selectedSankeyItems;
        List<SankeyItem> data;

        public List<SankeyItem> Data {
            get {
                if (data == null)
                    data = GetData();
                return data;
            }
        }
        public IList<object> SelectedSankeyItems {
            get { return selectedSankeyItems; }
            set {
                if (selectedSankeyItems != value) {
                    if (selectedSankeyItems is ObservableCollection<object>)
                        ((ObservableCollection<object>)selectedSankeyItems).CollectionChanged -= SelectedSankeyItems_CollectionChanged;
                    selectedSankeyItems = value;
                    if (selectedSankeyItems is ObservableCollection<object>)
                        ((ObservableCollection<object>)selectedSankeyItems).CollectionChanged += SelectedSankeyItems_CollectionChanged;
                    OnPropertyChanged("SelectedSankeyItems");
                }
            }
        }

        public SankeyViewModel() {
            ObservableCollection<object> collection = new ObservableCollection<object>();
            collection.CollectionChanged += SelectedSankeyItems_CollectionChanged;
            selectedSankeyItems = collection;
            selectedSankeyItems.Add("France");
            selectedSankeyItems.Add(Data[0]);
            selectedSankeyItems.Add(Data[2]);
            selectedSankeyItems.Add(Data[5]);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        void SelectedSankeyItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
        }
        void OnPropertyChanged(string propertyName) {
            PropertyChangedEventHandler propertyChangedEventHendler = PropertyChanged;
            if (propertyChangedEventHendler != null)
                propertyChangedEventHendler(this, new PropertyChangedEventArgs(propertyName));
        }

        public List<SankeyItem> GetData() {
            List<SankeyItem> data = new List<SankeyItem>{
                new SankeyItem { Source = "France", Target = "UK", Value = 53 },
                new SankeyItem { Source = "Australia", Target = "UK", Value = 72 },
                new SankeyItem { Source = "France", Target = "Canada", Value = 81 },
                new SankeyItem { Source = "China", Target = "Canada", Value = 96 },
                new SankeyItem { Source = "UK", Target = "France", Value = 61 },
                new SankeyItem { Source = "Canada", Target = "France", Value = 89 }
            };
            return data;
        }
    }
    public class SankeyItem {
        public string Source { get; set; }
        public string Target { get; set; }
        public double Value { get; set; }
    }
}
vb
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports DevExpress.Xpf.Charts.Sankey

Namespace WpfApp1
    Public Partial Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub
    End Class

    Public Class SankeyViewModel
        Implements INotifyPropertyChanged

        Private selectedSankeyItemsField As IList(Of Object)
        Private dataField As List(Of SankeyItem)

        Public ReadOnly Property Data As List(Of SankeyItem)
            Get
                If dataField Is Nothing Then dataField = GetData()
                Return dataField
            End Get
        End Property

        Public Property SelectedSankeyItems As IList(Of Object)
            Get
                Return selectedSankeyItemsField
            End Get
            Set(ByVal value As IList(Of Object))

                If selectedSankeyItemsField IsNot value Then
                    If TypeOf selectedSankeyItemsField Is ObservableCollection(Of Object) Then RemoveHandler CType(selectedSankeyItemsField, ObservableCollection(Of Object)).CollectionChanged, AddressOf SelectedSankeyItems_CollectionChanged
                    selectedSankeyItemsField = value
                    If TypeOf selectedSankeyItemsField Is ObservableCollection(Of Object) Then AddHandler CType(selectedSankeyItemsField, ObservableCollection(Of Object)).CollectionChanged, AddressOf SelectedSankeyItems_CollectionChanged
                    OnPropertyChanged("SelectedSankeyItems")
                End If
            End Set
        End Property

        Public Sub New()
            Dim collection As ObservableCollection(Of Object) = New ObservableCollection(Of Object)()
            AddHandler collection.CollectionChanged, AddressOf SelectedSankeyItems_CollectionChanged
            selectedSankeyItemsField = collection
            selectedSankeyItemsField.Add("France")
            selectedSankeyItemsField.Add(Data(0))
            selectedSankeyItemsField.Add(Data(2))
            selectedSankeyItemsField.Add(Data(5))
        End Sub

        Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

        Private Sub SelectedSankeyItems_CollectionChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
        End Sub

        Private Sub OnPropertyChanged(ByVal propertyName As String)
            Dim propertyChangedEventHendler As PropertyChangedEventHandler = PropertyChangedEvent
            If propertyChangedEventHendler IsNot Nothing Then propertyChangedEventHendler(Me, New PropertyChangedEventArgs(propertyName))
        End Sub

        Public Function GetData() As List(Of SankeyItem)
            Dim data As List(Of SankeyItem) = New List(Of SankeyItem) From {
                New SankeyItem With {
                    .Source = "France",
                    .Target = "UK",
                    .Value = 53
                },
                New SankeyItem With {
                    .Source = "Australia",
                    .Target = "UK",
                    .Value = 72
                },
                New SankeyItem With {
                    .Source = "France",
                    .Target = "Canada",
                    .Value = 81
                },
                New SankeyItem With {
                    .Source = "China",
                    .Target = "Canada",
                    .Value = 96
                },
                New SankeyItem With {
                    .Source = "UK",
                    .Target = "France",
                    .Value = 61
                },
                New SankeyItem With {
                    .Source = "Canada",
                    .Target = "France",
                    .Value = 89
                }
            }
            Return data
        End Function
    End Class

    Public Class SankeyItem
        Public Property Source As String
        Public Property Target As String
        Public Property Value As Double
    End Class
End Namespace

See Also

SankeyDiagramControl Class

SankeyDiagramControl Members

DevExpress.Xpf.Charts.Sankey Namespace