Back to Devexpress

LegendBase.CustomItemsSource Property

wpf-devexpress-dot-xpf-dot-charts-dot-legendbase-9aac575a.md

latest3.5 KB
Original Source

LegendBase.CustomItemsSource Property

Gets or sets the collection of objects used to generate custom legend items.

Namespace : DevExpress.Xpf.Charts

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

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public IEnumerable CustomItemsSource { get; set; }
vb
Public Property CustomItemsSource As IEnumerable

Property Value

TypeDescription
IEnumerable

A collection that is used to generate custom legend items. The default is null ( Nothing in Visual Basic).

|

Remarks

The following example generates custom legend items based on a collection of data objects:

xaml
<Window.DataContext>
    <local:ChartViewModel />
</Window.DataContext>
<!--...-->
<ChartControl>
    <dxc:ChartControl.Legends>
        <dxc:Legend x:Name="legend" 
                    Orientation="Vertical" 
                    CustomItemsSource="{Binding Path=CustomLegendItems}">
            <dxc:Legend.CustomItemTemplate>
                <DataTemplate>
                    <dxc:CustomLegendItem Text="{Binding Path=Text}" 
                                          MarkerBrush="{Binding Path=Brush}"/>
                </DataTemplate>
            </dxc:Legend.CustomItemTemplate>
        </dxc:Legend>
    </dxc:ChartControl.Legends>
<!--...-->
<ChartControl>
csharp
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Media;

namespace DxSample {
    public class ChartViewModel {
        public ObservableCollection<LegendItem> CustomLegendItems { get; set; }
        public ChartViewModel() {
            CustomLegendItems = new ObservableCollection<LegendItem>();
            CustomLegendItems.Add(new LegendItem { Text = "Custom Item 1", Brush = Brushes.Red });
            CustomLegendItems.Add(new LegendItem { Text = "Custom Item 2", Brush = Brushes.Green });
    }

    public class LegendItem {
        public string Text { get; set; }
        public Brush Brush { get; set; }
    }
}
vb
Imports System.Collections.ObjectModel
Imports System.Windows.Media

Namespace DxSample
    Public Class ChartViewModel
        Public Property CustomLegendItems As ObservableCollection(Of LegendItem)

        Public Sub New()
            CustomLegendItems = New ObservableCollection(Of LegendItem)()
            CustomLegendItems.Add(New LegendItem With {
                .Text = "Custom Item 1",
                .Brush = Brushes.Red
            })
            CustomLegendItems.Add(New LegendItem With {
                .Text = "Custom Item 2",
                .Brush = Brushes.Green
            })
        End Sub

        Public Class LegendItem
            Public Property Text As String
            Public Property Brush As Brush
        End Class
    End Class
End Namespace

See Also

LegendBase Class

LegendBase Members

DevExpress.Xpf.Charts Namespace