Back to Devexpress

ConstantLine.LegendMarkerTemplate Property

wpf-devexpress-dot-xpf-dot-charts-dot-constantline-ca2cf00e.md

latest8.8 KB
Original Source

ConstantLine.LegendMarkerTemplate Property

Gets or sets the template that defines the legend marker presentation for this constant line.

Namespace : DevExpress.Xpf.Charts

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

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public DataTemplate LegendMarkerTemplate { get; set; }
vb
Public Property LegendMarkerTemplate As DataTemplate

Property Value

TypeDescription
DataTemplate

A DataTemplate object that contains the template for a legend marker.

|

Example

This example shows how to apply the LegendMarkerTemplate property to change a constant line‘s marker at design time and runtime.

Use the following API members to create and customize a constant line:

MemberDescription
Axis2D.ConstantLinesInFrontProvides access to the axis’ collection of constant lines that are drawn in front of series. This is a dependency property.
ConstantLineRepresents a constant line of an axis.
ConstantLine.ValueGets or sets the constant line‘s position along an axis.
ConstantLine.LegendTextGets or sets the legend’s text for the constant line.
ConstantLine.LegendMarkerTemplateGets or sets the template that defines the legend marker presentation for this constant line.
ConstantLine.LineStyleSpecifies the constant line‘s style settings.
xaml
<Window x:Class="WpfApplication14.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" 
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts">
    <Grid>
        <dxc:ChartControl Name="chartControl1">
            <dxc:ChartControl.Resources>
                <DataTemplate x:Key="LegendMarkerTemplate">
                    <Border BorderThickness="1" 
                            BorderBrush="{Binding Path=MarkerLineBrush}">
                        <Path x:Name = "MarkerPath"
                              Stretch="Fill"
                              Fill="{Binding Path=MarkerBrush}"
                              Stroke="{Binding Path=MarkerLineBrush}"
                              StrokeThickness="{Binding Path=MarkerLineStyle.Thickness}"
                              StrokeDashArray="{Binding Path=MarkerLineStyle.DashStyle.Dashes}"
                              StrokeDashOffset="{Binding Path=MarkerLineStyle.DashStyle.Offset}"
                              StrokeDashCap="{Binding Path=MarkerLineStyle.DashCap}"
                              StrokeLineJoin="{Binding Path=MarkerLineStyle.LineJoin}"
                              StrokeMiterLimit="{Binding Path=MarkerLineStyle.MiterLimit}"
                              SnapsToDevicePixels="True"
                              StrokeStartLineCap="Square"
                              StrokeEndLineCap="Square">
                            <Path.Data>
                                <LineGeometry StartPoint="0,0" EndPoint="10,0"/>
                            </Path.Data>
                        </Path>
                    </Border>
                </DataTemplate>
            </dxc:ChartControl.Resources>
            <dxc:ChartControl.Legends>
                <dxc:Legend/>
            </dxc:ChartControl.Legends>
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D>
                    <dxc:XYDiagram2D.AxisY>
                        <dxc:AxisY2D>
                            <dxc:AxisY2D.ConstantLinesInFront>
                                <dxc:ConstantLine Value="0.5" Brush="Green" 
                                                  LegendText="Design time CL" 
                                                  LegendMarkerTemplate="{StaticResource LegendMarkerTemplate}">
                                    <dxc:ConstantLine.LineStyle>
                                        <dxc:LineStyle Thickness="2" >
                                            <dxc:LineStyle.DashStyle>
                                                <DashStyle Dashes="2 2" />
                                            </dxc:LineStyle.DashStyle>
                                        </dxc:LineStyle>
                                    </dxc:ConstantLine.LineStyle>
                                </dxc:ConstantLine>
                            </dxc:AxisY2D.ConstantLinesInFront>
                        </dxc:AxisY2D>
                    </dxc:XYDiagram2D.AxisY>
                    <dxc:XYDiagram2D.Series>
                        <dxc:LineSeries2D DisplayName="Series" 
                                          MarkerVisible="True" 
                                          ShowInLegend="False">
                            <dxc:LineSeries2D.Points>
                                <dxc:SeriesPoint Argument="A" Value="3" />
                                <dxc:SeriesPoint Argument="B" Value="2" />
                                <dxc:SeriesPoint Argument="C" Value="3" />
                                <dxc:SeriesPoint Argument="D" Value="5" />
                            </dxc:LineSeries2D.Points>
                        </dxc:LineSeries2D>
                    </dxc:XYDiagram2D.Series>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
        </dxc:ChartControl>
    </Grid>
</Window>
csharp
using DevExpress.Xpf.Charts;
using System.Windows;

namespace WpfApplication14 {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            XYDiagram2D diagram = ((XYDiagram2D)chartControl1.Diagram);
            diagram.ActualAxisY.ConstantLinesBehind.Add(
                new ConstantLine() {
                    Value = 4.5,
                    LegendText = "Runtime CL",
                    LegendMarkerTemplate = chartControl1.FindResource("LegendMarkerTemplate") as DataTemplate
                });
        }
    }
}
vb
Imports DevExpress.Xpf.Charts
Imports System.Windows

Namespace WpfApplication14
    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
            Dim diagram As XYDiagram2D = (CType(chartControl1.Diagram, XYDiagram2D))
            diagram.ActualAxisY.ConstantLinesBehind.Add(New ConstantLine() With {
                .Value = 4.5,
                .LegendText = "Runtime CL",
                .LegendMarkerTemplate = TryCast(chartControl1.FindResource("LegendMarkerTemplate"), DataTemplate)
            })
        End Sub
    End Class
End Namespace

Implements

LegendMarkerTemplate

See Also

ConstantLine Class

ConstantLine Members

DevExpress.Xpf.Charts Namespace