How to set the window to sleep on WPF? - wpf

How to get the window to sleep mode when the Winter Sleep button is pressed with the controls in the picture like the screen.
We can also give the window an effect like this (with the effect of aero glass but I haven't found this effect in research).
Kış Uykusu = Winter Sleep
enter link description here
enter image description here

Related

Title bar color

How come that on one computer the WPF tile bar is blue and on another one white?
On another PC it is white, it has to do with computer version?
I don't do anything special in code.
There is a setting in Windows 10 under Settings > Personalization > Colors called Title bars and window borders. In the second image it must be off. By the way it's turned off by default.

Prevent WPF form from jumping up when onscreen-keyboard opens

Please how can we prevent a full screen WPF form from scrolling up when the onscreen keyboard appears?
See the white space below the blue background that appears once the onscreen keyboard opens (slides out)

wpf notifyicon context menu not centered on tray icon at 100% dpi

I'm using the wpf notifyicon (http://www.hardcodet.net/wpf-notifyicon)
When my laptop is at 100% dpi scaling, the left side of the context menu is centred on the tray icon, as expected.
When the laptop isn't at 100%, the context menu is pushed to the far right.
On high resolution laptop displays, 100% scaling is not the default.
Wherever my tray icon is positioned, that is, however far from the clock, the menu always pops up over the clock, as far to the bottom-right of the screen as is possible while remaining visible.
Note: I'm testing on a default installation of Windows 8.1. Also, the NotifyIcon that I'm using is the one that is generally recommended for anyone attempting tray functionality in WPF.
To reproduce: the problem exists in the windowless sample provided by hardcodet. I'm using wpf NotifyIcon without a window, and can reproduce easily in code or xaml. In fact, I cannot stop reproducing it. It occurs when dpi scaling is turned on, i.e. when a 1080p display is actually showing a lesser resolution, which is what windows does to stop applications having text too tiny to read.
Any ideas about how I can make the context menu appear in the expected place regardless of dpi?
Screen shots as suggested by kennyzx:
good behaviour. the m on red background (MEGAsync) has just been right-clicked
bad behaviour. the green tick, my notifyicon, has just been right-clicked and the menu appears over the clock
!good behaviour. the m on red background (MEGAsync) has just been right-clicked
!bad behaviour. the green tick, my notifyicon, has just been right-clicked and the menu appears over the clock
and some code:
var n = new TaskbarIcon();
n.Icon=new System.Drawing.Icon(#"C:\window - 64 - tick.ico");
n.ContextMenu = new System.Windows.Controls.ContextMenu();
n.ContextMenu.Items.Add(new System.Windows.Controls.MenuItem {Header="E_xit" });
Found the solution here: http://www.codeproject.com/Messages/4929452/Problem-with-context-menu-position.aspx
It is, with thanks to codeproject user Igorious:
Get the code for Wpf Notifyicon (http://www.hardcodet.net/wpf-notifyicon)).
In Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ShowContextMenu()
replace
ContextMenu.HorizontalOffset = cursorPosition.X;
ContextMenu.VerticalOffset = cursorPosition.Y;
with
var g = Graphics.FromHwnd(IntPtr.Zero);
var scaleX = g.DpiX / 96.0;
var scaleY = g.DpiY / 96.0;
ContextMenu.HorizontalOffset = cursorPosition.X / scaleX;
ContextMenu.VerticalOffset = cursorPosition.Y / scaleY;
Explanation (thanks to codeproject user yachting):
It's needed because WinApi.GetPhysicalCursorPos return the mouse position in pixel,
but WPF's measurement unit is device independent pixel (by definition, it's 1/96 inch)
You need to adjust the return value of GetPhysicalCursorPos by DPI (dots per inch) setting,
otherwise the position of the context menu will be incorrect if users set DPI other than the default 96.

SDL2 - show overlay on mouse motion and hide it some time after mouse stopped

As the title says I'm trying to accomplish an overlay menu in my SDL2 application.
I have a window where I want to show an overlay menu if the mouse starts moving and show it as long the mouse moves. If the mouse stops moving a timer should start with a specific timeout and should hide the menu after the timeout has passed.
I tried using mouse events like SDL_MOUSEMOTION, but that doesn't work. I would rather need something like "mouse motion stopped" events, where I then would start the timer.
I then thought I could combine SDL_MOUSEMOTION with SDL_GetRelativeMouseState() and compare the mouse position deltas and start the timer if the deltas are 0. But that kind of seems too complicated. Is the latter the way to go, or is there a simpler way?
There are several ways you could approach this:
SDL doesn't send 'mouse motion stopped' events but conceptually, a 'mouse motion stopped' event is a frame where you haven't received a mouse motion event. If you have a frame update loop, keep track of whether you've received a mouse motion event in the previous frame and update your menu timer accordingly.
Simply reset your menu's timer every time you receive a SDL_MouseMotion event. It's not elegant but it should work. Run the menu timer as soon as you receive the first motion event and just reset the timer each time you receive a subsequent one until it expires and you hide the menu.

Windows Forms User Control not painting well in WPF application

So, this is the issue:
I have a Windows Forms User Control that I placed in main Window of my WPF application. I override paint method of User Control. It paints ok in "ideal" case. But, after showing the control in main window, I added MessageBox. This is the code snippet:
board = new BoggleBoard(Boggle.CurrentGame.Size);
boardHost.Child = board;
MessageBox.Show("You have " + time + " seconds to find as many words as you can. Click OK when you are ready to play);
If I don't show MessageBox, everything is ok. But with the code above, after MessageBox is shown, my control is painted, but just like boardHost (Windows Form Host) has lower opacity, so I get dark area around the control. I say "like" cause I tried with
boardHost.Opacity = 1;
but it doesn't help, I still get the same thing.
What might cause this problem?
Here is a screenshot. As obvious, the dark area around the board should not be there. And it is not visible if I don't show MessageBox after it is drawn.
http://i.stack.imgur.com/RZs2W.png

Resources