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);
// }
Application.Current.MainWindow
Using this you can access the MainWindow from any place.
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(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With