How to get screen bounds and change cursors in WinUI3 Desktop applications?
See original GitHub issueI need to achieve below requirements in WinUI 3 Desktop environment.
-
How to get display screen bounds?
-
How to change windows cursor type in desktop environment?
I already did this in WinUI UWP applications.
For Screen bounds,
var visibleBounds = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds; var scaleFactor = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; Size screenSize = new Size((visibleBounds.Width scaleFactor), (visibleBounds.Height scaleFactor));
For Cursor:
Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeNorthwestSoutheast, 0);
Anyone please suggest how to achieve same requirement in WinUI Desktop applications?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How to get screenbounds for WinUI3 Desktop applications?
I need to achieve below requirements in WinUI 3 Desktop applications. How to get screen bounds? How to change windows cursor type in...
Read more >How to get screen bounds for WinUI 3 Desktop application?
How to change windows cursor type in runtime? I already did this in WinUI UWP applications. For Screen bounds, var visibleBounds = Windows.UI....
Read more >Untitled
Wpf change cursor in xaml WebMay 20, 2013 · You can set the Cursor property ... How to get screen bounds and change...
Read more >How to Highlight Mouse Pointer Windows 10 - YouTube
In this step-by-step tutorial video, learn how to highlight your mouse cursor to make it easier for your audience to follow your mouse ......
Read more >Getting Display Information in Windows UI 3
How to obtain information on the active display in a Windows UI 3 app.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For the Cursor, there is a new API for this:
You can set this property and it will handle it all for you. The only problem is that you need to have a subclass of UIElement to access it.
For DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel, you need to get the XamlRoot.RasterizationScale.
Hi @KanniyappanP
I had the same experience of using
ProtectedCursor
and finding that the mouse pointer didn’t change, really wound me up for a while but I needed to give the user the visual feedback of being busy so perservered.Firstly I can confirm that
ProtectedCursor
does work, so stick with it.The issue I found was as part of the action setting the cursor, I was also
IsEnabled = false
the containingUserControl
as a quick way of showing the user that the TextBoxes were not available. By removing theIsEnabled = false
it started to work.I would recommend you go back to small steps, just set the cursor with no other side affects, convince yourself that it works and then build up the functionality you want and find out where the conflict occurs.
Another thought is that you might find that your action is fully synchronous and never yields the thread to change the pointer. You might try inserting a
await Task.Delay(1000)
to force a yield? Or do the work on another thread usingTask.Run ...
?Hope that helps, best of luck …