Change cursor in Windows Store Apps

感情迁移 提交于 2019-12-28 06:28:26

问题


I'm making a Windows Store app in C# and I have a normal TextBlock with a link inside it. And all I want to do it to make the cursor change into a hand when it goes over the text block, but unlike in WPF applications, there is no Cursor propriety. I know is a CoreCursor class in Windows.UI.Core. Am I suppose to use it somehow?


回答1:


Window.Current.CoreWindow.PointerCursor = 
    new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);



回答2:


WinRT XAML Toolkit has an attached property that works just about the same as the Cursor property in WPF in that you set a cursor for an element and so when your mouse cursor hovers on top of that element - the cursor changes to what the property specifies and when it leaves control bounds - it restores the previous cursor. There are actually two properties - one called FrameworkElementExtensions.SystemCursor that takes any standard cursor from the CoreCursorType enum, which you just use like in this sample page - set

<Border
    xmlns:Extensions="using:WinRTXamlToolkit.Controls.Extensions"
    Extensions:FrameworkElementExtensions.SystemCursor="Cross"/>

The other one - FrameworkElementExtensions.Cursor allows you to set any custom cursor, but I believe you'd need to set it in code behind like FrameworkElementExtensions.SetCursor(myElement, myCursor); or bind to a cursor property set elsewhere.

You can also use custom cursors. You need to define a cursor in a native resource library as described in this article and then you should be able to set them either globally by setting the Window.Current.CoreWindow.PointerCursor property or with an attached property like my FrameworkElementExtensions.Cursor.



来源:https://stackoverflow.com/questions/7472202/change-cursor-in-windows-store-apps

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