How to set Mouse Cursor in XAML / WPF?

只谈情不闲聊 提交于 2019-12-13 02:12:09

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/35311116/how-to-set-mouse-cursor-in-xaml-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!