Reputation: 325
In an WP app which approach is better.
From the .xaml page, call a method of another class (pass the delegate of a .xaml.cs callback Method ) which makes some request to server , receives data and when requests complete calls the .xaml.cs page method. and in call back method we get data and bind the data with a control (ListBox).
Bind the List box with an ObservableCollection object of MainViewModel class. and change the bounded object from the MainViewModel. All the calls to requests to server are made in MainViewModel class.
Upvotes: 3
Views: 174
Reputation: 2179
I think you should use the second approach which allows you to create loosely-coupled applications. The big advantages of such applications are:
Regarding WP7, you can read my article which shows how to code using this approach: a framework for building of WP7 application
Upvotes: 0
Reputation: 4344
I vote for the option 2. Event the project templates (Eg. Databound application template for Windows Phone 7) gives you the MainViewModel
and binds a Listbox
to an ObservableCollection
in that class.
The MVVC
approach gives you a lot more flexibility, your UI is totally separated from the logic. ALl your UI needs to know is that it is bound to an ObservableCollection
and it doesn't need to know how that collection is filled.
Upvotes: 4