Change mouse pointer in UWP app

社会主义新天地 提交于 2019-12-05 01:50:26

Yes this can be done by settings the Window.Current.CoreWindow.PointerCursor. If you set it to null, the pointer is hidden. Otherwise you can use the CoreCursorType enumeration to set a specific system point. For instance use this to set the Arrow type:

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

You can also add custom pointers by using a resource file. For details, see this blogpost.

No this is not possible to hide cursor but you can use another icons like:

  • Hand
  • Arrow
  • Cross
  • Custom
  • Hand
  • Help
  • IBeam

Use xaml Button and add PointerEntered event inside Button Control like:

<Button Name="button"  BorderThickness="2" PointerEntered="button_PointerEntered"  PointerExited="button_PointerExited">Button</Button>

and c# code:

 private void button_PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);
    }
    private void button_PointerExited(object sender, PointerRoutedEventArgs e)
    {
        Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1);
    }

Install the NuGet Package Microsoft.Toolkit.Uwp.UI from the Windows Community Toolkit.

After doing so, you can use the following code:

<Page ...
 xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions">

<UIElement extensions:Mouse.Cursor="Hand"/>

You can hide the cursor in UWP (C++ example)

            Windows::UI::Core::CoreWindow^ window = Windows::UI::Core::CoreWindow::GetForCurrentThread();
            window->PointerPosition = Point(ScreenXMid, ScreenYMid);
            window->PointerCursor = nullptr;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!