Back to Devexpress

SankeyDiagramControl.HighlightedItems Property

wpf-devexpress-dot-xpf-dot-charts-dot-sankey-dot-sankeydiagramcontrol-021de9ac.md

latest8.3 KB
Original Source

SankeyDiagramControl.HighlightedItems Property

Gets or sets the collection of data objects that are used to create highlighted 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 HighlightedItems { get; set; }
vb
<NonCategorized>
Public Property HighlightedItems As IList

Property Value

TypeDescription
IList

The collection of of data objects that are used to create highlighted links and nodes.

|

Remarks

The following example highlights an item and displays the highlighted item in a label:

xaml
<Window
    x:Class="WpfApplication2.MainWindow"
    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:dxsa="http://schemas.devexpress.com/winfx/2008/xaml/sankey"
    xmlns:local="clr-namespace:WpfApplication2"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Width="640"
    Height="420"
    mc:Ignorable="d"
    Title="MainWindow">
    <Window.DataContext>
        <local:SankeyViewModel />
    </Window.DataContext>
    <Grid>
        <dxsa:SankeyDiagramControl
            x:Name="sankeyDiagramControl1"
            DataSource="{Binding Data}"
            HighlightedItems="{Binding HighlightedItems}"
            SourceDataMember="Source"
            TargetDataMember="Target"
            WeightDataMember="Value">
            <dxsa:SankeyDiagramControl.Titles>
                <dxsa:SankeyTitle HorizontalAlignment="Center" Content="Export/Import" />
            </dxsa:SankeyDiagramControl.Titles>
        </dxsa:SankeyDiagramControl>
        <Button
            Margin="0,0,140,10"
            HorizontalAlignment="Right"
            VerticalAlignment="Bottom"
            Command="{Binding HighlightCommand}"
            Content="Highlight 'France'" />
        <Label Content="{Binding HighlightedItem}"
            HorizontalAlignment="Right"
            HorizontalContentAlignment="Left"
            VerticalAlignment="Bottom" Margin="0,0,30,10" Width="105"/>

    </Grid>
</Window>
csharp
public class SankeyViewModel : ViewModelBase {
    readonly ObservableCollection<object> highlightedItems;

    public object HighlightedItem {
        get {
            string text = string.Empty;
            if(highlightedItems.Count > 0) {
                if(highlightedItems[0] is SankeyItem)
                    text = ((SankeyItem)highlightedItems[0]).Value.ToString();
                else
                    text = highlightedItems[0].ToString();
            }
            else
                text = "(none)";
            return "Current: " + text;
        }
    }
    public ObservableCollection<object> HighlightedItems { get { return highlightedItems; } }
    public DelegateCommand HighlightCommand { get; private set; }
    public List<SankeyItem> Data {
        get { return GetData(); }
    }

    public SankeyViewModel() {
        HighlightCommand = new DelegateCommand(HighlightCommandExecute, HighlightCommandCanExecute);
        highlightedItems = new ObservableCollection<object>();
        highlightedItems.CollectionChanged += HighlightedItems_CollectionChanged;
    }
    void HighlightedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
        RaisePropertyChanged("HighlightedItem");
    }
    bool HighlightCommandCanExecute() {
        return true;
    }
    void HighlightCommandExecute() {
        highlightedItems.Clear();
        highlightedItems.Add("France");
    }
    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
Public Class SankeyViewModel
    Inherits ViewModelBase

    Private _HighlightCommand As DelegateCommand
    Private ReadOnly highlightedItemsField As ObservableCollection(Of Object)

    Public ReadOnly Property HighlightedItem As Object
        Get
            Dim text As String = String.Empty

            If highlightedItemsField.Count > 0 Then

                If TypeOf highlightedItemsField(0) Is SankeyItem Then
                    text = CType(highlightedItemsField(CInt(0)), SankeyItem).Value.ToString()
                Else
                    text = highlightedItemsField(0).ToString()
                End If
            Else
                text = "(none)"
            End If

            Return "Current: " & text
        End Get
    End Property

    Public ReadOnly Property HighlightedItems As ObservableCollection(Of Object)
        Get
            Return highlightedItemsField
        End Get
    End Property

    Public Property HighlightCommand As DelegateCommand
        Get
            Return _HighlightCommand
        End Get
        Private Set(ByVal value As DelegateCommand)
            _HighlightCommand = value
        End Set
    End Property

    Public ReadOnly Property Data As List(Of SankeyItem)
        Get
            Return GetData()
        End Get
    End Property

    Public Sub New()
        HighlightCommand = New DelegateCommand(AddressOf HighlightCommandExecute, AddressOf HighlightCommandCanExecute)
        highlightedItemsField = New ObservableCollection(Of Object)()
        Me.highlightedItemsField.CollectionChanged += AddressOf HighlightedItems_CollectionChanged
    End Sub

    Private Sub HighlightedItems_CollectionChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
        RaisePropertyChanged("HighlightedItem")
    End Sub

    Private Function HighlightCommandCanExecute() As Boolean
        Return True
    End Function

    Private Sub HighlightCommandExecute()
        highlightedItemsField.Clear()
        highlightedItemsField.Add("France")
    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

See Also

SankeyDiagramControl Class

SankeyDiagramControl Members

DevExpress.Xpf.Charts.Sankey Namespace