loris91
loris91

Reputation: 155

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??

Upvotes: 3

Views: 27837

Answers (2)

Nawed Nabi Zada
Nawed Nabi Zada

Reputation: 2875

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

Upvotes: 2

greg
greg

Reputation: 1314

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!

Upvotes: 2

Related Questions