Back to Devexpress

CrosshairLegendElement Class

wpf-devexpress-dot-xpf-dot-charts-3efd8a1d.md

latest6.4 KB
Original Source

CrosshairLegendElement Class

Defines the crosshair legend element’s appearance when custom drawing a crosshair cursor using the ChartControl.CustomDrawCrosshair event.

Namespace : DevExpress.Xpf.Charts

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

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public class CrosshairLegendElement :
    CrosshairLegendElementBase
vb
Public Class CrosshairLegendElement
    Inherits CrosshairLegendElementBase

Remarks

Use the CustomDrawCrosshairEventArgs.CrosshairLegendElements property to get access to the CrosshairLegendElement objects and customize their appearance.

Refer to Tooltip and Crosshair Cursor for more information.

Example

This example demonstrates how to modify the Crosshair Cursor’s appearance using the ChartControl.CustomDrawCrosshair event.

In this sample, crosshair content is displayed in a legend. For this, set the CrosshairOptions.ContentShowMode to the Legend value that the CrosshairContentShowMode enumeration contains. Note that you can specify the crosshair’s content show mode for the specified series using the XYSeries2D.CrosshairContentShowMode property.

Use the CustomDrawCrosshairEventArgs.CrosshairLegendElements property to obtain the crosshair legend elements’ collection.

To customize each crosshair legend element options, use the CrosshairLegendElement class properties.

csharp
using System.Windows;
using System.Windows.Media;
using DevExpress.Xpf.Charts;
namespace CustomDrawCrosshair {
    public partial class MainWindow : Window {
        const int ColorSelectorValue = 10;
        public MainWindow() {
            InitializeComponent();
        }
        private void OnCustomDrawCrosshair(object sender, CustomDrawCrosshairEventArgs e) {
            foreach(CrosshairLegendElement legendElement in e.CrosshairLegendElements) {
                legendElement.Foreground = (legendElement.SeriesPoint.Value > ColorSelectorValue) ? Brushes.Green : Brushes.Red;
                legendElement.LineElement.Brush = legendElement.Foreground;
                legendElement.AxisLabelElement.Background = legendElement.Foreground;
            }            
        }
    }
}
vb
Imports System.Windows
Imports System.Windows.Media
Imports DevExpress.Xpf.Charts

Namespace CustomDrawCrosshair

    Public Partial Class MainWindow
        Inherits Window

        Const ColorSelectorValue As Integer = 10

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub OnCustomDrawCrosshair(ByVal sender As Object, ByVal e As CustomDrawCrosshairEventArgs)
            For Each legendElement As CrosshairLegendElement In e.CrosshairLegendElements
                legendElement.Foreground = If((legendElement.SeriesPoint.Value > ColorSelectorValue), Brushes.Green, Brushes.Red)
                legendElement.LineElement.Brush = legendElement.Foreground
                legendElement.AxisLabelElement.Background = legendElement.Foreground
            Next
        End Sub
    End Class
End Namespace
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:CustomDrawCrosshair"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" 
        x:Class="CustomDrawCrosshair.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <dxc:ChartControl CustomDrawCrosshair="OnCustomDrawCrosshair">
            <dxc:ChartControl.CrosshairOptions>
                <dxc:CrosshairOptions ContentShowMode="Legend"
                                      ShowValueLabels="True"
                                      ShowValueLine="True"/>
            </dxc:ChartControl.CrosshairOptions>
            <dxc:ChartControl.Legends>
                <dxc:Legend/>
            </dxc:ChartControl.Legends>
            <dxc:XYDiagram2D>
                <dxc:BarSideBySideSeries2D DisplayName="Series1">
                    <dxc:SeriesPoint Argument="A" Value="8.452"/>
                    <dxc:SeriesPoint Argument="B" Value="13.697"/>
                    <dxc:SeriesPoint Argument="C" Value="9.147"/>
                    <dxc:SeriesPoint Argument="D" Value="12.186"/>
                    <dxc:SeriesPoint Argument="E" Value="10.82"/>
                </dxc:BarSideBySideSeries2D>
                <dxc:BarSideBySideSeries2D DisplayName="Series2">
                    <dxc:SeriesPoint Argument="A" Value="10.89"/>
                    <dxc:SeriesPoint Argument="B" Value="8.254"/>
                    <dxc:SeriesPoint Argument="C" Value="11.196"/>
                    <dxc:SeriesPoint Argument="D" Value="13.327"/>
                    <dxc:SeriesPoint Argument="E" Value="9.75"/>
                </dxc:BarSideBySideSeries2D>
            </dxc:XYDiagram2D>
        </dxc:ChartControl>
    </Grid>
</Window>

Inheritance

Object CrosshairLabelElementBase CrosshairLegendElementBase CrosshairLegendElement

See Also

CrosshairLegendElement Members

DevExpress.Xpf.Charts Namespace