#709 – Changing the Cursor

You can change the image displayed as a cursor in your WPF application by setting the Cursor property of any FrameworkElement.    You can set the cursor to one of the predefined Cursor objects in the System.Windows.Input.Cursors class.

In the example below, we set the cursor to a hand whenever the user moves the mouse over the blue label. Setting the Cursor property to null resets it to the default cursor.

    <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="45">
        <Label Content="Hey, move your mouse over me !" Background="AliceBlue" Padding="15,10"
                MouseEnter="Label_MouseEnter" MouseLeave="Label_MouseLeave"/>


        private void Label_MouseEnter(object sender, MouseEventArgs e)
            this.Cursor = Cursors.Hand;

        private void Label_MouseLeave(object sender, MouseEventArgs e)
            this.Cursor = null;