简体   繁体   中英

WPF C# Frame Navigation from page navigated

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.

Can you help me please??

If I understand correctly, you want to navigate from one page to another using a 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.

How to Build, Manage and Navigate the User Interface of a WPF Application

Simple Navigation

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!

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);
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM