Wpf – How to set Mouse Cursor in XAML / WPF

wpfwpf-controlsxaml

How can I set the Mouse cursor in xaml?

What's the use of Cursor property in every control? Please don't answer as Cursor="Arrow" cause this is not working.

Only way I can do it right now is from code behind by
Mouse.OverrideCursor. Can I do it simply using XMAL?

I have a Hierarchy of controls where there is a GridSplitter in between somewhere. I'm trying to set the Cursor to SizeNS but it's set to default as default Arrow. What Should I do?

Best Answer

In WPF Cursor creates problem when controls are declared in hierarchy and properties get overwritten.

If you strictly want to set Cursor in a control use ForceCursor property of FrameworkElement class.

Syntax:

    <StackPanel Name="CursorForced" ForceCursor="true" Cursor="Hand">
        <Label>Cursors Forced</Label>
        <TextBox>Fill me in!</TextBox>
    </StackPanel>

In above example if I don't use ForceCursor the Cursor will be different over TextBox not as I defined in parent control.

MSDN link to How to Force Cursor

Related Topic