4

I have a page transition ( a control ) in the MainWindow , I have many user control pages , I want to access the page transition in the MainWindow from my user control page ? How do I do that? I tried :

        Story page = new Story();
        NavigationService nav = NavigationService.GetNavigationService(this);
        // Navigate to the page, using the NavigationService
      //  if (nav != null)
       // { 
        //    nav.Navigate(page);
            MainWindow test = new MainWindow();
            test.pageTransition1.ShowPage(page);

    //    }
paary
  • 421
  • 6
  • 16
user2376998
  • 1,061
  • 7
  • 32
  • 65

3 Answers3

12
Application.Current.MainWindow

Using this you can access the MainWindow from any place.

Jawahar
  • 4,775
  • 1
  • 24
  • 47
2

You could find the WpfPageTransitions.PageTransition control like this from the UserControls code behind:

public static WpfPageTransitions.PageTransition FindPageControl(DependencyObject child)
{
    DependencyObject parent= VisualTreeHelper.GetParent(child);

    if (parent == null) return null;

    WpfPageTransitions.PageTransition page = parent as WpfPageTransitions.PageTransition;
    if (page != null)
    {
        return page;
    }
    else
    {
        return FindPageControl(parent);
    }
}

Then you can use it like this:

this.FindPageControl(this).ShowPage(...);
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • hey thanks for the reply but PageTransition is not a WPF control , i added in the control from other source .. – user2376998 Jul 10 '13 at 04:50
  • so when i do the above , PageTransition will be missing – user2376998 Jul 10 '13 at 04:51
  • i added reference of the page transition and add to controls tab , i got this page transitions from here : http://www.codeproject.com/Articles/197132/Simple-WPF-Page-Transitions – user2376998 Jul 10 '13 at 09:25
  • You will just have to reference the object with it's full namespace. I've edited my code. Perhaps you could edit your question too, this would clarify it for other users. – Romano Zumbé Jul 10 '13 at 09:36
1

Create A Method Inside Main Window for Choosing Page Transition

 public   void ChangePage()
        {
            pageTransitionControl.ShowPage(new NewData());
        }

Then in Child control

private void btnUpdate_Click(object sender,RoutedEventArgs e)
        {

            MainWindow win = (MainWindow)Window.GetWindow(this);
            win.ChangePage();
        }
Muhamed Shafeeq
  • 1,194
  • 1
  • 9
  • 15