如何使用 WPF 中的代码将页面添加到框架 [英] How to add a Page to Frame using code in WPF
问题描述
我有一个窗口,我在其中放置了一个框架.当我单击一个也在窗口上但不在框架中的按钮时,我想将一个页面添加到框架中.Window 中有多个按钮,每次单击按钮都会在 Frame 中加载不同的页面.
I have a Window where I have put a Frame. I would like to add a Page to the Frame when I click a button that is also on the Window but not in the Frame. There are several buttons in the Window and each click on a button should load a different Page in the Frame.
因为我是这个 WPF 东西的新手,所以这种方法很可能不是最好的,我已经考虑过用画布替换框架,然后制作用户控件而不是将添加到画布的页面.我欢迎任何关于如何最好地解决这个问题的想法和建议.
Since I'm a total newbie on this WPF stuff it's quite possible that this approach is not the best and I have thought about replacing the Frame with a Canvas and then make UserControls instead of Pages that will be added to the Canvas. I welcome any ideas and suggestions on how to best solve this.
我的目标是与比利霍利斯在 dnrtv 第 115 集中演示的应用程序类似的功能.(http://dnrtv.com/default.aspx?showID=115).
I aiming for a functionality that is similar to the application Billy Hollis demonstrated in dnrtv episode 115. (http://dnrtv.com/default.aspx?showID=115).
推荐答案
Frame 类公开了一个名为Navigate"的方法,该方法将要在框架中显示的内容作为参数.试试打电话
the Frame class exposes a method named "Navigate" that takes the content you want to show in your frame as parameter. try calling
myFrame.Navigate(myPageObject);
这应该有效
这篇关于如何使用 WPF 中的代码将页面添加到框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!