// When page is navigated to set data context to selected item in itemType protected override void OnNavigatedTo(NavigationEventArgs e) { // trace data TraceHelper.AddMessage("ListPage: OnNavigatedTo"); // handle list picker navigation cases if (sortPopupOpen == true) { SortPopup.IsOpen = true; return; } if (importPopupOpen == true) { ImportListPopup.IsOpen = true; return; } string IDString = ""; Guid id; // get the type of list to display if (NavigationContext.QueryString.TryGetValue("type", out typeString) == false) { // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID of the object to display if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID id = new Guid(IDString); switch (typeString) { case "Folder": // get the folder and make it the datacontext try { folder = App.ViewModel.LoadFolder(id); // if the load failed, this folder has been deleted if (folder == null) { // the folder isn't found - this can happen when the folder we were just // editing was removed in FolderEditor, which then goes back to ListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID of the list to display if (NavigationContext.QueryString.TryGetValue("ParentID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID id = new Guid(IDString); // get the current list name string listName = null; Guid? listID = null; Guid itemTypeID; if (id == Guid.Empty) { listName = folder.Name; itemTypeID = folder.ItemTypeID; } else { var item = folder.Items.Single(i => i.ID == id); listName = item.Name; listID = (Guid?)id; itemTypeID = item.ItemTypeID; // change the "edit folder" appbar button title to "edit list" ApplicationBarIconButton button = null; for (int i = 0; i < ApplicationBar.Buttons.Count; i++) { button = (ApplicationBarIconButton)ApplicationBar.Buttons[i]; if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase)) break; } if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase)) button.Text = "edit list"; } // construct a synthetic item that represents the list of items for which the // ParentID is the parent. this also works for the root list in a folder, which // is represented with a ParentID of Guid.Empty. list = new Item() { ID = id, Name = listName, FolderID = folder.ID, IsList = true, ItemTypeID = itemTypeID, Items = folder.Items.Where(i => i.ParentID == listID).ToObservableCollection() }; } catch (Exception ex) { // the folder isn't found - this can happen when the folder we were just // editing was removed in FolderEditor, which then goes back to ListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage(String.Format("ListPage: Navigate back (exception: {0})", ex.Message)); // navigate back NavigateBack(); return; } break; case "Tag": // create a filter try { tag = App.ViewModel.Tags.Single(t => t.ID == id); // construct a synthetic item that represents the list of items which // have this tag. list = new Item() { ID = Guid.Empty, Name = String.Format("items with {0} tag", tag.Name), Items = App.ViewModel.Items.Where(t => t.ItemTags.Any(tg => tg.TagID == tag.ID)).ToObservableCollection() }; } catch (Exception) { // the tag isn't found - this can happen when the tag we were just // editing was removed in TagEditor, which then goes back to ListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } break; default: // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // set datacontext ListGrid.DataContext = list; // create the ListHelper ListHelper = new ListHelper( new RoutedEventHandler(CompleteCheckbox_Click), new RoutedEventHandler(Tag_HyperlinkButton_Click)); // store the current listbox and ordering ListHelper.ListBox = ItemsListBox; ListHelper.OrderBy = ListMetadataHelper.GetListSortOrder( App.ViewModel.PhoneClientFolder, id == Guid.Empty ? (ClientEntity) folder : (ClientEntity) list); // trace data TraceHelper.AddMessage("Exiting ListPage OnNavigatedTo"); }
// When page is navigated to set data context to selected item in itemType protected override void OnNavigatedTo(NavigationEventArgs e) { // trace data TraceHelper.AddMessage("ListPage: OnNavigatedTo"); // handle list picker navigation cases if (sortPopupOpen == true) { SortPopup.IsOpen = true; return; } if (importPopupOpen == true) { ImportListPopup.IsOpen = true; return; } string IDString = ""; Guid id; // get the type of list to display if (NavigationContext.QueryString.TryGetValue("type", out typeString) == false) { // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID of the object to display if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID id = new Guid(IDString); switch (typeString) { case "Folder": // get the folder and make it the datacontext try { folder = App.ViewModel.LoadFolder(id); // if the load failed, this folder has been deleted if (folder == null) { // the folder isn't found - this can happen when the folder we were just // editing was removed in FolderEditor, which then goes back to ListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID of the list to display if (NavigationContext.QueryString.TryGetValue("ParentID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // get the ID id = new Guid(IDString); // get the current list name string listName = null; Guid? listID = null; Guid itemTypeID; if (id == Guid.Empty) { listName = folder.Name; itemTypeID = folder.ItemTypeID; } else { var item = folder.Items.Single(i => i.ID == id); listName = item.Name; listID = (Guid?)id; itemTypeID = item.ItemTypeID; // change the "edit folder" appbar button title to "edit list" ApplicationBarIconButton button = null; for (int i = 0; i < ApplicationBar.Buttons.Count; i++) { button = (ApplicationBarIconButton)ApplicationBar.Buttons[i]; if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase)) { break; } } if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase)) { button.Text = "edit list"; } } // construct a synthetic item that represents the list of items for which the // ParentID is the parent. this also works for the root list in a folder, which // is represented with a ParentID of Guid.Empty. list = new Item() { ID = id, Name = listName, FolderID = folder.ID, IsList = true, ItemTypeID = itemTypeID, Items = folder.Items.Where(i => i.ParentID == listID).ToObservableCollection() }; } catch (Exception ex) { // the folder isn't found - this can happen when the folder we were just // editing was removed in FolderEditor, which then goes back to ListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage(String.Format("ListPage: Navigate back (exception: {0})", ex.Message)); // navigate back NavigateBack(); return; } break; case "Tag": // create a filter try { tag = App.ViewModel.Tags.Single(t => t.ID == id); // construct a synthetic item that represents the list of items which // have this tag. list = new Item() { ID = Guid.Empty, Name = String.Format("items with {0} tag", tag.Name), Items = App.ViewModel.Items.Where(t => t.ItemTags.Any(tg => tg.TagID == tag.ID)).ToObservableCollection() }; } catch (Exception) { // the tag isn't found - this can happen when the tag we were just // editing was removed in TagEditor, which then goes back to ListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } break; default: // trace page navigation TraceHelper.StartMessage("ListPage: Navigate back"); // navigate back NavigateBack(); return; } // set datacontext ListGrid.DataContext = list; // create the ListHelper ListHelper = new ListHelper( new RoutedEventHandler(CompleteCheckbox_Click), new RoutedEventHandler(Tag_HyperlinkButton_Click)); // store the current listbox and ordering ListHelper.ListBox = ItemsListBox; ListHelper.OrderBy = ListMetadataHelper.GetListSortOrder( App.ViewModel.PhoneClientFolder, id == Guid.Empty ? (ClientEntity)folder : (ClientEntity)list); // trace data TraceHelper.AddMessage("Exiting ListPage OnNavigatedTo"); }