Frage

I'm trying to find a way to nudge a WPF window (similar effect to how msn messenger window used to nudge). I know some people will say I shouldn't do this, but it is to meet a specific user requirement. By nudge I mean shake the window location about for about half a second (I'm not interested in sound like the MSN one, as the customer environment doesn't allow sound).

I will also be bringing the window to the front (but I already know how to do that).

The reason for this is to get across to the end user when an extremely important event occurs.

I'm using WPF XAML and c# in the application

I'm considering moving the window at random on a timer, but also wondering if I can acheive this via XAML?

War es hilfreich?

Lösung

Ok, I've found out how to do this by modifying some code from a code project sample that did it for windows forms. http://www.codeproject.com/Articles/10131/Simulate-the-quot-Nudge-quot-Effect

public  void NudgeWindow(Window window)
{
    var maxOffset = 9;
    var minOffset = 1; 
    var originalLeft = (int) window.Left;
    var originalTop = (int) window.Top;
    var rnd = 0;

    var RandomClass = new Random();
    for (int i = 0; i <= 500; i++)
    {
        rnd = RandomClass.Next(originalLeft + minOffset, originalLeft + maxOffset);
        window.Left = rnd;
        rnd = RandomClass.Next(originalTop + minOffset, originalTop + maxOffset);
        window.Top = rnd;
    }
    window.Left = originalLeft;
    window.Top = originalTop;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top