Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Mouse Cursor in XAML / WPF?

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 XAML?

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?

like image 572
Kylo Ren Avatar asked Sep 14 '25 18:09

Kylo Ren


1 Answers

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

like image 128
Kylo Ren Avatar answered Sep 16 '25 17:09

Kylo Ren