从页面导航的 WPF C# 框架导航
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15683635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF C# Frame Navigation from page navigated
提问by loris91
i've a windows and a frame in this windows. the frame navigate in a page and into this page i've a button. The page was created dinamically so, i want to add a event onclick of button into the page, that permit me to navigate a new page into frame of window.
我在这个窗口中有一个窗口和一个框架。框架在页面中导航并进入此页面,我有一个按钮。该页面是动态创建的,所以我想在页面中添加一个按钮点击事件,这允许我将新页面导航到窗口框架中。
i'm writing on google about custom event that can permit me to raise an event in a page that is related to event in a window.
我正在 google 上写关于自定义事件的文章,该事件可以允许我在与窗口中的事件相关的页面中引发事件。
Can you help me please??
你能帮我吗??
回答by greg
If I understand correctly, you want to navigate from one page to another using a event
?
如果我理解正确,您想使用event
?
If that is the case, take a look at the following links below - these will give you a better understanding of navigating through a WPF application providing examples and sample apps.
如果是这种情况,请查看下面的以下链接 - 这些链接将让您更好地了解通过提供示例和示例应用程序的 WPF 应用程序进行导航。
How to Build, Manage and Navigate the User Interface of a WPF Application
This is how I achieve it. In the code behind of your application, do something like this to help navigate to the next page for your click event;
这就是我实现它的方式。在应用程序背后的代码中,执行以下操作以帮助导航到单击事件的下一页;
private void btnClick_HomeClick(object sender, RoutedEventArgs e)
{
FrameContent.Navigate(new ExampleView()); //FrameContent is the name given to the frame within the xaml.
}
Hope this helps!
希望这可以帮助!
回答by Nawed Nabi Zada
I guess the scenario here is that he has a Window with a frame and the navigation method is also in this window.
我猜这里的场景是他有一个带框架的窗口,导航方法也在这个窗口中。
What you can do is to pass your window to those dynamically created pages.
您可以做的是将您的窗口传递给那些动态创建的页面。
//Main Window
public class MainWindow
{
public void NavigatePage(Page page)
{
YourFrameInstance.Navigate(page)
}
}
//Your Page
public class Page
{
private readonly Window _mainWindow;
public Page(Window mainWindow)
{
_mainWindow = mainWindow;
}
void Button_Click(object sender, RoutedEventArgs e)
{
var page = new Page(_mainWindow);
_mainWindow.NavigatePage(page);
}
}