Back to Devexpress

CrosshairOptions.ContentShowMode Property

wpf-devexpress-dot-xpf-dot-charts-dot-crosshairoptions-bc9d04d3.md

latest6.9 KB
Original Source

CrosshairOptions.ContentShowMode Property

Gets or sets the element that displays the Crosshair’s content.

Namespace : DevExpress.Xpf.Charts

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

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public CrosshairContentShowMode ContentShowMode { get; set; }
vb
Public Property ContentShowMode As CrosshairContentShowMode

Property Value

TypeDescription
CrosshairContentShowMode

The value that specifies the chart element displaying the Crosshair’s content.

|

Available values:

NameDescription
Default

The default mode.

| | Label |

The Crosshair’s label displays information about the series point that the Crosshair Cursor highlights.

| | Legend |

A legend displays information about the series point that the Crosshair Cursor highlights.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to ContentShowMode
ChartControl

.CrosshairOptions .ContentShowMode

|

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>

See Also

CrosshairOptions Class

CrosshairOptions Members

DevExpress.Xpf.Charts Namespace