c# - Communicate between pages in wpf -


i have 2 pages , 1 mainwindow.. load pages in 2 frames.. want execute methods each other.. how can this?

this page1.cs:

public partial class page1 : page {     public method1()     {         dosomething;                 } } 

this page2.cs:

public partial class page2 : page {     public method2()     {         dosomethingelse;                 } } 

in mainwindow following happens:

frame1.source = new uri("/source/pages/page1.xaml", urikind.relativeorabsolute); frame2.source = new uri("/source/pages/page2.xaml", urikind.relativeorabsolute); 

is there way, execute method2 page1.cs, , method1 page2.cs?

regards

one way through common parent, window.

looking @ (modified accordingly)

public partial class mainwindow : window {     public page1 page1ref = null;     public page1 page2ref = null;      public mainwindow()     {         initializecomponent();     }      private void window_loaded(object sender, routedeventargs e)     {         frame1.source = new uri("/source/pages/page1.xaml", urikind.relative);         frame1.contentrendered += frame1_contentrendered;          // same frame2     }      private void frame1_contentrendered(object sender, eventargs e)     {         var b = frame1.content page1; // home.xaml         page1ref = b;         if(page2ref != null) // because don't know of pages gets rendered first         {            page2ref.page1ref = page1ref; // add page1ref prop page2 class             page1ref.page2ref = page2ref;  // here same         }      }     // same other page } 

from this question

you should able set reference once page loaded other page .

better yet, might want let pages know of window parent , access other page through it. either way, bad design, i'm telling you.

is not solution proud of, might better mvvm, , go it. let me know if worked you.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -