0

我想通过 WPF 制作一个包含几页的程序。

我现在有一个Window和几个Page

为了导航,我使用

this.Content = new Page1();

在主窗口中(从WindowPage),以及

((Window)this.Parent).Content = new Page1();

页面之间(从PagePage),因为Page只能是Windowor的子元素Frame

但是,上面的第二行代码看起来很丑。

有没有更好的方法来实现相同的目标?

我之前从几个 Windows Phone 应用程序中编写过代码,我认为在 s 之间导航可能Page比隐藏/显示元素(例如Grids)更好。

4

2 回答 2

1

如果您的导航代码在您的 Page 类上,则:

  • 将其移至窗口类
  • 在 Page 类中创建一个事件,并在 Window 类中对其作出反应。
于 2012-07-30T09:22:20.117 回答
0

有什么理由不能在 Window 中放一个 Frame 吗?

您可以使用 NavigationService。

http://msdn.microsoft.com/en-us/library/ms750478.aspx

http://www.paulstovell.com/wpf-navigation

也许这会有所帮助:

http://azerdark.wordpress.com/2010/04/23/multi-page-application-in-wpf/

于 2012-07-30T09:23:17.763 回答