0

I have a Windows Modern App with a custom cursor, that is implemented by having an image that follows the system's cursor.

I just add the custom cursor image to the main grid of my application and everything works fine.

public MainPage() : base(true)
{
    this.InitializeComponent();
    MainPageGrid.Children.Add(new CustomCursor());
}

But when a popup opens, it gets above my custom cursor. Is there anyway that I can set the Z-index (or something similar) of a component in order for it to be the uppermost visual component of my modern application?

  • 1
    sounds like you may need to look into `Active Window` and then check for that ..once you know that the popup is the active window or is in the forefront.. then set your custom cursor.. but can't tell without seeing any code – MethodMan Sep 19 '14 at 13:41
  • I added the code I'm using, hope it helps. Meanwhile, I will be checking the `Active Window` as you suggested. – João Lourenço Sep 19 '14 at 14:43
  • 1
    Well I would say that a `Popup` is a special control, it is shown on top of all the windows except the topmost ones. Only the actual mouse (not fake mouse) can hover on it. Anyway you should use a `Window` or even a `Popup` to fake the cursor (the CustomCursor), then you can set it as topmost so that it can lay on top of the popup. – King King Sep 19 '14 at 16:32
  • Actually I'm using a popup but it won't stay above other popups. Even opening and closing the CustomCursor popup does not display it above others... – João Lourenço Sep 23 '14 at 15:04

2 Answers2

1

I would recommend using an actual custom cursor. I think this article looks like a decent intro to using these. You could also check this question for some tips on changing cursors. Other than that - I don't think you can tell when a random popup opens. You can poll for these with VisualTreeHelper.GetOpenPopups(), and then do something to make your popup show on top (maybe just reopening would work or maybe you'd need to create a new one every time) but that might not give you a good user experience or performance. You could also figure out all the events that could display a popup from ComboBoxes, Flyouts etc, but that sounds painful. It would probably be best to create an attached behavior that you could attach to all such popup-source-elements to trigger z-index fix-ups of your XAML-rendered custom cursor...

Community
  • 1
  • 1
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • Thanks for your answer. I cannot customize the system's cursor as the maximum size allowed is 32x32p, and mine is much bigger. As I answered to a previous comment, just opening and closing the popup won't display it above other popups. I'll try the solution you suggested of creating a new popup and then I'll tell you how it worked out. – João Lourenço Sep 23 '14 at 15:07
  • It does not work creating a new Popup either... I think this problem occurs because I'm adding my cursor in the main grid `MainPageGrid.Children.Add(new CustomCursor());`, so everything that is above that grid will be above my cursor. But where should I had my CustomCursor then? – João Lourenço Sep 23 '14 at 15:26
  • Try using the `VisualTreeHelper` to get the topmost element. I think even `Window.Current.Content` isn't the topmost one, so you need to find it. – Filip Skakun Sep 23 '14 at 15:29
  • 1
    I think you might be able to make cursors larger than 32x32. Check [this article](http://forums.codeguru.com/showthread.php?231312-Make-Cursor-bigger-than-32x32) or search for [others on the topic.](https://www.bing.com/search?q=mouse%20cursor%20larger%20than%2032x32) It seems like it might involve using an icon file as a cursor, but I think it should work and would work a lot better than hacking it with XAML. – Filip Skakun Sep 23 '14 at 16:56
  • 1
    One tool to create larger animated cursors that I found: http://www.rw-designer.com/cursor-maker From what I could see though - it seems like you might be able to create a 256x256 one even in VS 2013. I haven't checked though if you can load these... – Filip Skakun Sep 23 '14 at 22:18
  • Thank you very much @FilipSkakun ! With your help I've been able to find a way to increase the cursor size. You are a life savior! :D – João Lourenço Sep 25 '14 at 17:21
0

There is no need to implement a component as a custom cursor, as it is possible to override the maximum size limitation: How to override maximum 32x32 mouse size in Windows like this program can

Community
  • 1
  • 1