开发者

WPF multiple windows in the same location after another

If there's a WPF project with a lot of windows of the same size, what should I do to make the windows be in the same location while switching between them. For example there's one window,开发者_运维百科 I click next button to hide this window and show the second, next window appears but it is in another place. How to control the place of window apperance?


Set all the windows to have the same Height/Width and Left and Top properties and stack them behind each other.

But you can just change your approach altogether. You have change your Windows to be be Page and use NavigationService.

See http://msdn.microsoft.com/en-us/library/ms750478.aspx http://www.paulstovell.com/wpf-navigation


Have a look at a Wizard Control, there are many more just search the web.

That it will save you from reinventing the wheel and littering the taskbar.


if you want to have a second window in the center of the first window you must use it:

1 - Set this property of the second window WindowStartupLocation = CenterOwner 2 - In the first window and in your button Click event (or everywhere you want) write this:

SecondWindow s = new SecondWindow();
s.owner = this;
s.ShowDialog();


There are some good suggestions here but an approach I might use is to have your main window contain a ContentControl that takes up the space where you want the windows to appear. Then, make each of your windows a UserControl. This will allow you to assign any of these UserControl windows to the ContentControl. This method is well-suited when using MVVM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜