0

Hi guys so I have a WPF application where my main window contains two frames within it like so.

<Window> <Frame source="term.xaml"/> <Frame source="flag.xaml"/> </Window>

I am trying to share data between term and flag.xaml. They both have their own .XAML.cs and I cannot figure out how on a button click to move data from term to flag. Could someone lead me in the right direction.

Note this is a flat program meaning there is only one screen that holds both of these frames within the main window.

Both term and flag are partial classes that are pages.

wdlax11
  • 822
  • 3
  • 11
  • 29
  • 1
    If they are both bound to the same viewmodel then they'll be sharing the same data. – slugster Jul 24 '18 at 12:42
  • I can't manage to access it. I have check boxes on flag.xaml and I am trying to get that value in term.xaml.cs. How would I do that? For example I can't just type in the variable name in term for the checkbox in flag that variable is not found. – wdlax11 Jul 24 '18 at 12:44
  • @slugster, then ViewModel has to be a singleton or passed there from some parent context like Window, otherwise two separate instances will be created and no data sharing will be available except that the shared data will be static... – Andrew K Jul 24 '18 at 13:08
  • But the main question to the author is why do you want to use Frames? They should be only used when you want to have navigation (see [here](http://paulstovell.com/blog/wpf-navigation)). – Andrew K Jul 24 '18 at 13:11
  • In general if you want to send some data from one view to another, you need to have some communication service with pub/sub mechanism. The best option is to make use of some existing WPF frameworks like Prism or MVVMLight. – Andrew K Jul 24 '18 at 13:14
  • Andrew I inhered this and my code was setup like this with a Window then 2 pages on the window. All of them need to interact so I am trying to make it work :/ does something like this potentially work? https://stackoverflow.com/questions/18878103/how-to-pass-data-between-wpf-page-and-a-window the data I'm passing is on button clicks – wdlax11 Jul 24 '18 at 13:15
  • Something like [this](https://dzone.com/articles/implement-a-simple-messenger-for-mvvm-user-control) or [this](https://www.c-sharpcorner.com/UploadFile/20c06b/messaging-system-in-wpf/) should work and that will be a better approach. – Andrew K Jul 25 '18 at 11:42

0 Answers0