Access Pivot Control from App.xaml.cs?

Up vote 0 down vote favorite share g+ share fb share tw.

In my MainPage. Xaml, I created a Pivot Control: . My first pivot view is a HubTile that summarize all other individual pages.

So my application bar will be different between the first pivot view and all other ones. That's why I put my application bar in App. Xaml's resource section, then load based on selected index of my pivot.

My question is: In the application bar I will be using for all individual pages, I want to have a delete option, where I will remove that specific item (a view model) from my data context. I know I can use PhoneApplicationFrame root = Application.Current. RootVisual as PhoneApplicationFrame; to access navigation services, but I don't know how can I reference to my pivot, so that I can get the selected index and proceed forward.

Thanks! C# windows-phone-7 windows-phone-7.1 windows-phone-7.5 link|improve this question asked Feb 9 at 3:21Derek Lee737110 94% accept rate.

Using MVVM you SHOULDN'T do this: ((PageType)Application.Current. RootVisual).PivotControl. //Blah PageType is whatever type PhoneApplicationFrame is that contains your PivotControl.

If this doesn't work you need a Property in the RootVisual PAGE public Pivot MyPivot { get { return PivotControl; } } APP ((PageType)RootVisual).MyPivot. //Blah.

On one level Microsoft's suggestion of putting the ApplicationBar in App. Xaml is great as it can be referenced from everywhere and would appear to encourage code reuse: however this question highlights the limit to this approach. An application bar is typically used to provide actions which are specific to the current page (or pivot item) and just because the buttons are the same you may not want the exact same code to run in each case.

In this case I think it would better to create a factory method that creates your common ApplicationBar with the click handlers you specify specific to your page/pivot item. For bonus points put the method in a new class (not App) so it doesn't get lost in all the boilerplate code there. Call this factory method in your page constructor and remember your ApplicationBar in your class.

For multiple app bars, create them all up front and you can then easily switch between these app bars in your Pivot SelectionChanged code. The alternative of creating the ApplicationBar in App. Xaml and then retrieving this from the App.xaml.

Cs "Resources" ResourceDictionary in code, modifying the click callbacks, is more complicated in my opinion. I wish they'd done a better job of implementing the ApplicationBar so people wouldn't want to do this. I've found that using the ApplicationBar forces you to add code to your Page.xaml.

Cs even if you use a framework like MVVM Light. This is still OK in MVVM as it's UI specific code that belongs in the View, but it makes things inconsistent if you're using ICommand everywhere else. Last time I decided it was better to create the entire ApplicationBar in code rather than hack this kind of thing via App.xaml.cs.

Update: There is a UserVoice request for a data bindable ApplicationBar.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions