0
votes

i have a textblock in mainpage.xaml. I have another page which has a textblock whose value is bound to observable collection and its value changes depending on user events on that page. How can i bind the textblock value in this other page to textblock value in mainpage.xaml?

Can anybody please guide me to any resources or examples which may explain how to do this or any workaround?

1
How do you navigate from one page to another? Can you pass the value from one page to another page? - kimsk
why wouldn't you bind both textblocks to the viewmodel (observable collection)? - Jim O'Neil

1 Answers

1
votes

Well, you can't directly bind properties of two controls on different pages since they aren't displayed at the same time. You'll need to store your state elsewhere and retrieve the values from there.

Basically you'll need to store your application state somewhere, either inside the App class or singleton/static properties. Alternativelly you could persist the state between pages (to a file or setting) and retrieve it again when loading the page.

In any case you should bind the controls in both pages to a view model which would retrieve the values from the application state or itself be stored there. This way the values set from one page will reflect on the other one.

Depending on how you navigate between pages you might be able to take advantage of parameters as well (Frame.Navigate(typeof(OtherPage), parameter)) but you're limited to tranferring only basic types this way, so you'll be able to transfer ids but not complete objects.