ChartControl.CustomDrawCrosshair Event
Occurs before crosshair items are drawn when the chart’s contents are being drawn.
Namespace: DevExpress.Xpf.Charts
Assembly: DevExpress.Xpf.Charts.v19.1.dll
Declaration
Event Data
The CustomDrawCrosshair event's data class is CustomDrawCrosshairEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
CrosshairAxisLabelElements | Gets the settings of crosshair axis label elements to customize their appearance. |
CrosshairElementGroups | Provides access to the settings of crosshair elements and crosshair group header elements to customize their appearance. |
CrosshairElements | Obsolete. Gets crosshair elements (crosshair value lines, crosshair value labels, crosshair labels) to customize their appearance. |
CrosshairGroupHeaderElements | Obsolete. Gets the settings of crosshair group header elements to customize their appearance. |
CrosshairLegendElements | Returns crosshair legend elements to customize their appearance. |
CrosshairLineElement | Gets the settings of a crosshair line element to customize its appearance (color, line style). |
Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs. |
IndicatorLegendElements | Returns all indicator elements that the Crosshair Cursor shows in a legend. |
OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs. |
Source | Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
InvokeEventHandler(Delegate, Object) | When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs. |
OnSetSource(Object) | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs. |
Remarks
Use the CustomDrawCrosshair event to create a custom appearance for crosshair items.
Example
This example shows how to provide a custom appearance for the crosshair cursor using the ChartControl.CustomDrawCrosshair
event. This event is invoked when you click the Custom Draw Crosshair Cursor button on the form.
If you wish to display crosshair axis lines and labels on a chart before custom drawing the crosshair cursor, set the CrosshairOptions.ShowArgumentLabels, CrosshairOptions.ShowArgumentLine, CrosshairOptions.ShowValueLabels and CrosshairOptionsBase.ShowValueLine properties to true.
Note that the customization of the crosshair cursor is provided for the CrosshairOptions.SnapMode property set to NearestArgument.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-custom-draw-a-crosshair-cursor-e4385.
<Window x:Class="CrosshairCustomDraw.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>
<StackPanel>
<dxc:ChartControl Height="269" Name="chartControl1" CustomDrawCrosshair="chartControl1_CustomDrawCrosshair">
<dxc:ChartControl.CrosshairOptions>
<dxc:CrosshairOptions ShowArgumentLabels="True" ShowArgumentLine="True"
ShowValueLabels="True" ShowValueLine="True"/>
</dxc:ChartControl.CrosshairOptions>
<dxc:XYDiagram2D>
<dxc:LineSeries2D DisplayName="Series1">
<dxc:SeriesPoint Argument="1" Value="50"/>
<dxc:SeriesPoint Argument="2" Value="44"/>
<dxc:SeriesPoint Argument="3" Value="55"/>
<dxc:SeriesPoint Argument="4" Value="77"/>
</dxc:LineSeries2D>
<dxc:LineSeries2D DisplayName="Series2">
<dxc:SeriesPoint Argument="1" Value="22"/>
<dxc:SeriesPoint Argument="2" Value="11"/>
<dxc:SeriesPoint Argument="3" Value="9"/>
<dxc:SeriesPoint Argument="4" Value="8"/>
</dxc:LineSeries2D>
</dxc:XYDiagram2D>
</dxc:ChartControl>
<Button Height="35" Content="Custom Draw Crosshair Cursor" Click="Button_Click"></Button>
</StackPanel>
</Grid>
</Window>
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawCrosshair event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.