Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

LegendBase.CustomItemTemplate Property

Gets or sets the DataTemplate that specifies how to convert a model object to a custom legend item.

Namespace: DevExpress.Xpf.Charts

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

NuGet Package: DevExpress.Wpf.Charts

#Declaration

public DataTemplate CustomItemTemplate { get; set; }

#Property Value

Type Description
DataTemplate

A DataTemplate that specifies a generated legend custom item’s parameters. The default is null (Nothing in Visual Basic).

#Remarks

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

<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>
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; }
    }
}
See Also