Back to Devexpress

ChartControl.QueryChartCursor Event

wpf-devexpress-dot-xpf-dot-charts-dot-chartcontrol-e79ba0d7.md

latest7.8 KB
Original Source

ChartControl.QueryChartCursor Event

Occurs when there is a request to display the cursor on the chart control.

Namespace : DevExpress.Xpf.Charts

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

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public event QueryChartCursorEventHandler QueryChartCursor
vb
Public Event QueryChartCursor As QueryChartCursorEventHandler

Event Data

The QueryChartCursor event's data class is QueryChartCursorEventArgs. The following properties provide information specific to this event:

PropertyDescription
CursorGets or sets the mouse cursor currently being shown for the chart.
CursorImageProvides an image for the custom cursor.
CursorImageOffsetSpecifies an image offset for a custom cursor on a chart diagram.
HandledGets 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.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
PositionGets or sets a value that specifies the position of a custom cursor on the chart’s diagram.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

MethodDescription
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

In the QueryChartCursor event handler, you can provide custom cursors for your chart in various circumstances (e.g. when a chart is being scrolled or zoomed).

Example

This example shows how to display a custom cursor when the mouse pointer is hovering over the chart control.

To accomplish this task, handle the ChartControl.QueryChartCursor event and assign your custom image (e.g., a BitmapImage object loaded from application resources) to the QueryChartCursorEventArgs.CursorImage property.

Note that you need to include your image in the project and set the QueryChartCursorEventArgs.Cursor property to None to see the custom image in the chart control.

xaml
<Window x:Class="CustomCursor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
        Title="MainWindow" Height="350" Width="525" >
    <Grid>
        <dxc:ChartControl Name="chartControl1" QueryChartCursor="chartControl1_QueryChartCursor">
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D >
                    <dxc:XYDiagram2D.Series>
                        <dxc:BarSideBySideSeries2D >
                            <dxc:BarSideBySideSeries2D.Points>
                                <dxc:SeriesPoint Argument="C" Value="5" />
                                <dxc:SeriesPoint Argument="B" Value="3" />
                                <dxc:SeriesPoint Argument="A" Value="1" />
                            </dxc:BarSideBySideSeries2D.Points>
                        </dxc:BarSideBySideSeries2D>
                    </dxc:XYDiagram2D.Series>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
        </dxc:ChartControl>
    </Grid>
</Window>
csharp
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using DevExpress.Xpf.Charts;

namespace CustomCursor {

    public partial class MainWindow : Window {

        public MainWindow() {
            InitializeComponent();
        }

        private void chartControl1_QueryChartCursor(object sender, QueryChartCursorEventArgs e) {
            e.Cursor = Cursors.None;
            e.CursorImage = new BitmapImage(new Uri(@"/CustomCursor;component/mycursor.png", UriKind.Relative));
        }

    }

}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Input
Imports System.Windows.Media.Imaging
Imports DevExpress.Xpf.Charts

Namespace CustomCursor

    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub chartControl1_QueryChartCursor(ByVal sender As Object, ByVal e As QueryChartCursorEventArgs)
            e.Cursor = Cursors.None
            e.CursorImage = New BitmapImage(New Uri("/CustomCursor;component/mycursor.png", UriKind.Relative))
        End Sub

    End Class

End Namespace

See Also

ChartControl Class

ChartControl Members

DevExpress.Xpf.Charts Namespace