Start position - what about end position

Jul 27, 2011 at 12:56 AM
Edited Jul 27, 2011 at 1:00 AM

Tim, super tool! Thanks.

fw.VerticalOffset and fw.HorizontalOffset work great to set the starting position of a floating window.

But I'd like to capture where that window ends up, dragged by the user, so that I can return it to that spot the next time they launch it.

I tried putting this in the Resize event handler - no help. 

FloatableWindow fw = sender as FloatableWindow;
if (fw != null) {
    this.cookiestorage.Top = (double)fw.GetValue(Canvas.TopProperty);
    this.cookiestorage.Left = (double)fw.GetValue(Canvas.LeftProperty);

The above simply returns the same settings I applied when I created the floating window and set the top/left. They've not been changed.

Tried just using the fw.VerticalOffset and HorizontalOffset again as property returns, but again, they contain the values originally set. No changes.

And I don't know what event I can sink to capture the event of the window move, but even if I did, still couldn't get the new coordinates from any property set I can think of.

Thanks for any help.


Jul 28, 2011 at 1:32 AM

Worked it out myself.


Add this to the Chrome_MouseMove event handler:

try {
  this._horizontalOffset += t.X;
  this._verticalOffset += t.Y;
 if (this.WindowMoveEvent != null)
   this.WindowMoveEvent(thisthis._horizontalOffset, this._verticalOffset);
catch { }


and added a move event and delegate

public delegate void DelegateWindowMove(object sender, double x, double y);

public event DelegateWindowMove WindowMoveEvent;

And then in my client side MDI app I handle the move and the resize with this to capture exactly where to put the window back at:


public void HandleViewSizeChangedEvent(object sender, SizeChangedEventArgs e) {
    this.view.Width = e.NewSize.Width;
    this.view.Height = e.NewSize.Height;

public void HandleViewLocationChangedEvent(object sender, double x, double y) {
    this.view.Top = y;
    this.view.Left = x;

So when I got back to re-show any Floating or MDI window:

FloatingWindow fw = new FloatingWindow();
fw.Title = view.ViewName;
fw.ParentLayoutRoot = this.viewContainer;
fw.Width = view.Width;
fw.Height = view.Height;
fw.VerticalOffset = view.Top;
fw.HorizontalOffset = view.Left;
fw.Content = viewClient;
fw.SizeChanged += viewClient.HandleViewSizeChangedEvent;
fw.WindowMoveEvent += viewClient.HandleViewLocationChangedEvent;