Giusepe Giusepe -4 years ago 79
C# Question

What is the best way to pass data between views?

I have done some research and still didn't found a solution that seems correct, in a "best practices" way.

I'm working on a App for iPhone using Xamarin. This app will be initial iPhone only, but there are plans to make versions for Android and Windows Phone in the near future.

This App crete/saves a "Moment". This moment have some pictures plus some information. Basically, this moment will be used all over the App, been incremented with more data from lots of views.
While I do save this moment to some kind of repository (SQL, filesystem, ..., I still have to implement this), I need it to be alive thru the workflow.

One way of doing it, would be:

var moment = new Moment()
// .. add infos from view to moment
nextView.Moment = moment;
PerformSegue(...);


Is this the right way of doing it? There isn't any pattern that I could use to solved it from all platforms and control better how to pass this infos between the views (samples would be appreciated)?

Answer Source

You could use the Singleton pattern to get access to your data in every point of your app.

Check out the Wiki page(with a sample): http://en.wikipedia.org/wiki/Singleton_pattern

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download