Darren Young
Darren Young

Reputation: 11090

c# WindowsPhone Organise Code in Pivot App

I'm writing my first Windows Phone app using the Pivot functionality. From what I understand it's pretty much a single view/page, that can be manipulated to show different data.

Each pivot item would be a distinct view in my mind. So how would you organise the code in an MVVM type way? Is this possible? By this I mean having a different view model for each pivot item, and binding data in the pivot items to the different viewmodels? As you only really have a single view, how can you set the datacontext to the different viewmodels? Should this be done dynamically when a new pivot item is displayed?

Is there a different preferred architecture model for pivot applications?

Thanks.

Upvotes: 1

Views: 308

Answers (1)

Martin Liversage
Martin Liversage

Reputation: 106826

One way to do this is to have a pivot view deriving from PhoneApplicationPage containing a Pivot control and a corresponding parent view model. For each pivot page you create a child view model and aggregate this in parent view model and you also create corresponding views derived from UserControl for the view models. You then aggregate the child views inside the pivot binding them to the child view models either manually or through databinding.

Upvotes: 1

Related Questions