If I add a XamDialogWindow to it by follwing code and then click Maximize button.
the XamDialogWindow's position is incorrect.
see attached project for the details
Hi,
That's because of the Horizontal and VerticalAlignment you set on the window. If you change the code to:
XamDialogWindow w = new XamDialogWindow(); w.StartupPosition = StartupPosition.Center; w.RestrictInContainer = true; //w.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; //w.VerticalAlignment = System.Windows.VerticalAlignment.Center; w.Height = 500; w.Width = 500;
The window will be positioned properly when maximized.
HTH
I know this solution. but if i set w.StartupPosition = StartupPosition.Center; I cannot change the top and left of XamDialogWindow anymore. My purpose is open XamDialogWindow in the center but if open second, we hope there is a margin between these 2 windows, so i need to change the top and left to achieve this.
hi,
Even if the StartupPosition is set to Center you still can change the Top and Left of the window. I've attached a modifed version of your sample that demonstrates that.
Regards
i want to set the top and left for initializing.so, if the code changed to
w = new XamDialogWindow(); w.StartupPosition = StartupPosition.Center; w.Height = 500; w.Width = 500; w.Top += 100; w.Left += 100; LayoutRoot.Children.Add(w);
the window is still in the center. it seems Set value for top and left doesn't work.
In the code above you set the Top and Left before you place the window inside the LayoutRoot. The XamWindow doesn't know it's parent container at that time and cannot calculate how to center itself. You have to set the new Top and Left after the window is arranged inside the container.
You can try this code:
w = new XamDialogWindow(); w.StartupPosition = StartupPosition.Center; w.Height = 500; w.Width = 500; LayoutRoot.Children.Add(w); this.Dispatcher.BeginInvoke(() => { w.Top += 100; w.Left += 100; });
Hi
It works! Thanks very much!
Thanks,