在 Windows 应用商店应用程序中更改光标
我正在用 C# 制作一个 Windows 应用商店应用程序,并且有一个普通的 TextBlock,其中有一个链接。我想做的就是让光标在经过文本块时变成一只手,但与 WPF 应用程序不同的是,没有 Cursor 属性。我知道 Windows.UI.Core 中有一个 CoreCursor 类。我应该以某种方式使用它吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WinRT XAML Toolkit 有一个附加属性,其工作方式与 WPF 中的
Cursor
属性几乎相同,因为您可以为元素设置光标,因此当鼠标光标悬停在该元素顶部时 - 光标更改属性指定的内容以及当它离开控制范围时 - 它会恢复前一个光标。实际上有两个属性 - 一个名为FrameworkElementExtensions.SystemCursor
从 CoreCursorType 枚举,您只需使用它就像此示例页面 - 设置另一个 -
FrameworkElementExtensions.Cursor
允许您设置任何自定义光标,但我相信您需要在后面的代码中设置它,例如FrameworkElementExtensions.SetCursor(myElement, myCursor);
或绑定到其他地方设置的光标属性。您还可以使用自定义光标。您需要在本机资源库中定义游标,如 这篇文章 然后您应该能够通过设置全局设置它们
Window.Current.CoreWindow.PointerCursor
属性或带有附加属性,例如我的FrameworkElementExtensions.Cursor
。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 calledFrameworkElementExtensions.SystemCursor
that takes any standard cursor from the CoreCursorType enum, which you just use like in this sample page - setThe other one -
FrameworkElementExtensions.Cursor
allows you to set any custom cursor, but I believe you'd need to set it in code behind likeFrameworkElementExtensions.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 myFrameworkElementExtensions.Cursor
.