EventPage.xaml.cs CampusAppWP8::Pages::Events::EventPage CampusAppWP8::Pages::Events //----------------------------------------------------------------------------- //<copyrightfile="EventPage.xaml.cs"company="BTU/IIT"> //Companycopyrighttag. //</copyright> //<author>fiedlchr</author> //<sience>03.05.2013</sience> //----------------------------------------------------------------------------- namespaceCampusAppWP8.Pages.Events { usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Windows; usingSystem.Windows.Controls; usingSystem.Windows.Navigation; usingCampusAppWP8.Model.RSS; usingCampusAppWP8.Resources; usingCampusAppWP8.Utility; usingMicrosoft.Phone.Controls; usingMicrosoft.Phone.Shell; publicpartialclassEventPage:PhoneApplicationPage { privateboolisSourceSet=false; privateintlastSelectedIndex=-1; privateboolisNewInstance=false; publicEventPage() { this.InitializeComponent(); ApplicationBarIconButtonlinkBtn=newApplicationBarIconButton(); linkBtn.IconUri=newUri(Icons.Link,UriKind.Relative); linkBtn.Text=AppResources.NewsLinkBtn; linkBtn.Click+=newEventHandler(this.EventLink_Click); ApplicationBar.Buttons.Add(linkBtn); this.isNewInstance=true; } protectedoverridevoidOnNavigatedTo(NavigationEventArgse) { base.OnNavigatedTo(e); if(this.isNewInstance) { if((EventIndexPage.GetEventFeed()==null)||(EventIndexPage.GetEventFeed().GetModel()==null)) { RSSViewModeltempModel=null; if((tempModel=App.LoadFromIsolatedStorage<RSSViewModel>(Constants.IsolatedStorage_EventRSSModel))!=null) { if(EventIndexPage.GetEventFeed()==null) { EventIndexPage.Feed=newFeed.Events.EventFeed(false); } EventIndexPage.Feed.Model=tempModel; this.isSourceSet=false; } } this.isNewInstance=false; } //SetpivotitemSource if(this.isSourceSet==false) { this.EventPivot.ItemsSource=EventIndexPage.GetEventFeed().Model.Channel[0].Item; this.isSourceSet=true; } stringpivotIndex=string.Empty; //Navigatetotheselectedpivotitem if(NavigationContext.QueryString.TryGetValue(Constants.ParamPivotIndex,outpivotIndex)) { intpivotIndexInt=int.Parse(pivotIndex); //iftheindexisintherangeofthearray if((pivotIndexInt>=0)&&(pivotIndexInt<EventIndexPage.GetEventFeed().Model.Channel[0].Item.Count())) { EventPivot.SelectedIndex=pivotIndexInt; } else { stringo=string.Empty; foreach(KeyValuePair<string,string>kvpinNavigationContext.QueryString) { o+=string.Format("Key={0},Value={1}",kvp.Key,kvp.Value)+"\n"; } MessageBox.Show("ERROR:pivotIndexoutofrange!!!("+o+")"); } } } protectedoverridevoidOnNavigatedFrom(NavigationEventArgse) { base.OnNavigatedFrom(e); if(e.NavigationMode!=System.Windows.Navigation.NavigationMode.Back) { App.SaveToIsolatedStorage<RSSViewModel>(Constants.IsolatedStorage_EventRSSModel,EventIndexPage.GetEventFeed().GetModel()); } } privatevoidOnPivotSelectionChange(objectsender,SelectionChangedEventArgse) { intselIndex=(senderasPivot).SelectedIndex; if(this.lastSelectedIndex>-1) { Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventWebBrowser",Visibility.Collapsed,this.lastSelectedIndex); Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",Visibility.Visible,this.lastSelectedIndex); } this.lastSelectedIndex=selIndex; } privatevoidEventLink_Click(objectsender,EventArgse) { if(Visibility.Visible==Utilities.GetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",this.EventPivot.SelectedIndex)) { Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",Visibility.Collapsed,this.EventPivot.SelectedIndex); Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventWebBrowser",Visibility.Visible,this.EventPivot.SelectedIndex); } else { Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventWebBrowser",Visibility.Collapsed,this.EventPivot.SelectedIndex); Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",Visibility.Visible,this.EventPivot.SelectedIndex); } } } }