Ishti
Ishti

Reputation: 325

In a Windows Phone app which approach is better?

In an WP app which approach is better.

  1. 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).

  2. 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

Answers (2)

Ilya Builuk
Ilya Builuk

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:

  • separation of concerns: different subsystems/layers are independent
  • unit testing is simple
  • refactoring is easier
  • increase ability to code reuse
  • ...

Regarding WP7, you can read my article which shows how to code using this approach: a framework for building of WP7 application

Upvotes: 0

texmex5
texmex5

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

Related Questions