/// <summary> /// Construct an instance of the MainPage view /// </summary> public MainPage() { InitializeComponent(); // Setup custom strings to replace some of PivotViewer's default strings (comment this line to use all defaults) System.Windows.Pivot.PivotViewer.SetResourceManager(SampleLocalizedStrings.ResourceManager); // Load the initial collection string initialCollectionUri; if (!App.Current.Host.InitParams.TryGetValue("initialCollectionUri", out initialCollectionUri)) { // Otherwise use the default startup collection initialCollectionUri = s_defaultStartupCollectionUri.ToString(); } PivotViewer.LoadCollection(initialCollectionUri, string.Empty); PivotViewer.CollectionLoadingFailed += new EventHandler <CollectionErrorEventArgs>(PivotViewer_CollectionLoadingFailed); // Enable the shopping cart (comment this line to disable the shopping cart) ShoppingCart.Create(PivotViewer); // Enable the travel log (comment this line to disable the travel log) TravelLog.Create(PivotViewer, new Uri(initialCollectionUri)); }
/// <summary> /// Helper to load a collection from a Uri that may contain a viewerState fragment /// </summary> private void LoadCollection(string collectionUri) { string baseCollectionUri; string viewerState; BreakupCollectionUri(collectionUri, out baseCollectionUri, out viewerState); PivotViewer.LoadCollection(baseCollectionUri, viewerState); }
private PivotViewerHistory(PivotViewer pivotViewer, Uri initialCollectionUri) { _pivotViewer = pivotViewer; _history = new Dictionary<string, PivotViewerHistoryEntry>(); _currentHistoryEntry = new PivotViewerHistoryEntry(initialCollectionUri, string.Empty); _pivotViewer.PropertyChanged += OnPropertyChanged; App.Current.Host.NavigationStateChanged += OnHostNavigationStateChanged; }
/// <summary> /// Construct a TravelLog connected to a PivotViewer /// </summary> private TravelLog(PivotViewer pivotViewer, Uri initialCollectionUri) { m_pivotViewer = pivotViewer; m_travelLog = new Dictionary<string, TravelLogEntry>(); m_currentTravelLogEntry = new TravelLogEntry(initialCollectionUri, string.Empty); // Hook the events that are needed to implement travel log m_pivotViewer.PropertyChanged += new PropertyChangedEventHandler(PivotViewer_PropertyChanged); App.Current.Host.NavigationStateChanged += OnHostNavigationStateChanged; }
/// <summary> /// Construct a TravelLog connected to a PivotViewer /// </summary> private TravelLog(PivotViewer pivotViewer, Uri initialCollectionUri) { m_pivotViewer = pivotViewer; m_travelLog = new Dictionary <string, TravelLogEntry>(); m_currentTravelLogEntry = new TravelLogEntry(initialCollectionUri, string.Empty); // Hook the events that are needed to implement travel log m_pivotViewer.PropertyChanged += new PropertyChangedEventHandler(PivotViewer_PropertyChanged); App.Current.Host.NavigationStateChanged += OnHostNavigationStateChanged; }
/// <summary> /// Create a singleton instance of the PivotViewerHistory and connect it to a PivotViewer. Because PivotViewerHistory /// reads/writes App.Current.Host.NavigationState, there should only be one instance of PivotViewerHistory in /// an application. /// </summary> public static void Create(PivotViewer pivotViewer, Uri initialCollectionUri) { if (_instance != null) throw new InvalidOperationException("PivotViewerHistory interacts with the application state, there should only be one instance in an application"); if (pivotViewer.CollectionUri != null) throw new InvalidOperationException("PivotViewerHistory should be connected to a PivotViewer before it has loaded a collection"); _instance = new PivotViewerHistory(pivotViewer, initialCollectionUri); }
/// <summary> /// Create a singleton instance of the TravelLog and connect it to a PivotViewer. Because TravelLog /// reads/writes App.Current.Host.NavigationState, there should only be one instance of TravelLog in /// an application. /// </summary> public static void Create(PivotViewer pivotViewer, Uri initialCollectionUri) { if (s_instance != null) { throw new InvalidOperationException("TravelLog interacts with the application state, there should only be one instance in an application"); } if (pivotViewer.CollectionUri != null) { throw new InvalidOperationException("TravelLog should be connected to a PivotViewer before it has loaded a collection"); } s_instance = new TravelLog(pivotViewer, initialCollectionUri); }
/// <summary> /// Create a singleton instance of the TravelLog and connect it to a PivotViewer. Because TravelLog /// reads/writes App.Current.Host.NavigationState, there should only be one instance of TravelLog in /// an application. /// </summary> public static void Create(PivotViewer pivotViewer, Uri initialCollectionUri) { if (s_instance != null) { throw new InvalidOperationException("TravelLog interacts with the application state, there should only be one instance in an application"); } if (pivotViewer.CollectionUri != null) { throw new InvalidOperationException("TravelLog should be connected to a PivotViewer before it has loaded a collection"); } s_instance = new TravelLog(pivotViewer, initialCollectionUri); }
/// <summary> /// Handle double-clicks on collection items /// </summary> private void PivotViewer_ItemDoubleClicked(object sender, ItemEventArgs args) { string linkUriString = PivotViewer.GetItem(args.ItemId).Href; if (!string.IsNullOrWhiteSpace(linkUriString)) { PivotViewer.CurrentItemId = args.ItemId; OpenLink(linkUriString); } else { ErrorWindow errorWin = new ErrorWindow("No Associated Web Page", "The item that was double-clicked has no value for the 'Href' field"); errorWin.Show(); } }
/// <summary> /// Handle a custom action execution /// </summary> private void PivotViewer_ItemActionExecuted(object sender, ItemActionEventArgs args) { PivotViewer pivotViewer = (PivotViewer)sender; // Add or remove the item from the cart, depending the action Id. if (args.CustomActionId == AddItemActionId) { m_itemIdsInCart.Add(args.ItemId); } else if (args.CustomActionId == RemoveItemActionId) { m_itemIdsInCart.Remove(args.ItemId); } // After an action has been executed, the ListBox is stale, so update it RefreshCartContentsListBox(); }
/// <summary> /// Apply pre-defined "American Cars" filter to new cars collection /// </summary> private void OnAmericanCarsClicked(object sender, RoutedEventArgs args) { PivotViewer.LoadCollection(s_bingNewCarsCollectionUri.ToString(), c_americanCarsViewerState); }
/// <summary> /// Load AMG Top-rated movies collection /// </summary> private void OnAMGTopMoviesClicked(object sender, RoutedEventArgs args) { PivotViewer.LoadCollection(s_AMGMoviesCollectionUri.ToString(), string.Empty); }
/// <summary> /// Load new cars collection /// </summary> private void OnCarsCollectionClicked(object sender, RoutedEventArgs args) { PivotViewer.LoadCollection(s_bingNewCarsCollectionUri.ToString(), string.Empty); }