// When page is navigated to set data context to selected item in listType protected override void OnNavigatedTo(NavigationEventArgs e) { // trace data TraceHelper.AddMessage("TaskList: OnNavigatedTo"); string IDString = ""; string typeString = ""; Guid id; if (NavigationContext.QueryString.TryGetValue("type", out typeString) == false) { // trace page navigation TraceHelper.StartMessage("TaskList: Navigate back"); // navigate back NavigationService.GoBack(); return; } switch (typeString) { case "TaskList": if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("TaskList: Navigate back"); // navigate back NavigationService.GoBack(); return; } id = new Guid(IDString); // get the tasklist and make it the datacontext try { taskList = App.ViewModel.TaskLists.Single(tl => tl.ID == id); SetContext(taskList); } catch (Exception ex) { // the list isn't found - this can happen when the list we were just // editing was removed in TaskListEditor, which then goes back to TaskListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage(String.Format("TaskList: Navigate back (exception: {0})", ex.Message)); // navigate back NavigationService.GoBack(); return; } break; case "Tag": if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("TaskList: Navigate back"); // navigate back NavigationService.GoBack(); return; } id = new Guid(IDString); // create a filter try { tag = App.ViewModel.Tags.Single(t => t.ID == id); taskList = new TaskList() { ID = Guid.Empty, Name = String.Format("tasks with {0} tag", tag.Name), Tasks = App.ViewModel.Tasks }; SetContext(taskList); foreach (var source in OrderedSource) source.Filter += new FilterEventHandler(Tag_Filter); } catch (Exception) { // the tag isn't found - this can happen when the tag we were just // editing was removed in TagListEditor, which then goes back to TaskListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("TaskList: Navigate back"); // navigate back NavigationService.GoBack(); return; } break; default: // trace page navigation TraceHelper.StartMessage("TaskList: Navigate back"); // navigate back NavigationService.GoBack(); return; } // workaround for the CollectionViewSource wrappers that are used for the different ListBox sorts // setting SelectionMode to Multiple removes the issue where the SelectionChanged event handler gets // invoked every time the list is changed (which triggers a re-sort). The SelectionMode gets reset back // to Single when the SelectionChanged events handler gets called (for a valid reason - i.e. user action) SetSelectionMode(SelectionMode.Multiple); // enable the listbox disableListBoxSelectionChanged = false; // trace data TraceHelper.AddMessage("Exiting TaskList OnNavigatedTo"); }
private void RenderEditTaskTagList(TextBox taglist, Task task, PropertyInfo pi) { taglist.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } }; // build the comma delimited tag list for this task bool addDelimiter = false; StringBuilder sb = new StringBuilder(); var tasktags = (IEnumerable<TaskTag>)pi.GetValue(task, null); if (tasktags != null) { foreach (TaskTag tt in tasktags) { if (addDelimiter) sb.Append(","); Tag tag = App.ViewModel.Tags.Single(t => t.ID == tt.TagID); sb.Append(tag.Name); addDelimiter = true; } taglist.Text = sb.ToString(); } // retrieve the tasktags for the task, creating new tags along the way taglist.LostFocus += new RoutedEventHandler(delegate { //ObservableCollection<TaskTag> existingTags = (ObservableCollection<TaskTag>)pi.GetValue(task, null); ObservableCollection<TaskTag> newTags = new ObservableCollection<TaskTag>(); string[] tags = taglist.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var tt in tags) { string str = tt.Trim(); Tag tag; try { tag = App.ViewModel.Tags.Single(t => t.Name == str); newTags.Add(new TaskTag() { Name = str, TagID = tag.ID, TaskID = task.ID }); } catch (Exception) { // this is a new tag that we need to create tag = new Tag() { Name = str }; newTags.Add(new TaskTag() { Name = str, TagID = tag.ID, TaskID = task.ID }); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord( new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = new Tag(tag) }); // add the tag to the tag list App.ViewModel.Tags.Add(tag); // save the changes to local storage StorageHelper.WriteTags(App.ViewModel.Tags); } } // store the new TaskTag collection in the task pi.SetValue(task, newTags, null); // create the mirror Tags collection in the task task.CreateTags(App.ViewModel.Tags); }); }
void TagEditor_Loaded(object sender, RoutedEventArgs e) { // trace event TraceHelper.AddMessage("TagEditor: Loaded"); ConnectedIconImage.DataContext = App.ViewModel; string tagIDString = ""; if (NavigationContext.QueryString.TryGetValue("ID", out tagIDString)) { if (tagIDString == "new") { // new tag tagCopy = new Tag(); DataContext = tagCopy; } else { Guid tagID = new Guid(tagIDString); tag = App.ViewModel.Tags.Single<Tag>(tl => tl.ID == tagID); // make a deep copy of the tag for local binding tagCopy = new Tag(tag); DataContext = tagCopy; // add the delete button to the ApplicationBar var button = new ApplicationBarIconButton() { Text = "Delete", IconUri = new Uri("/Images/appbar.delete.rest.png", UriKind.Relative) }; button.Click += new EventHandler(DeleteButton_Click); // insert after the save button but before the cancel button ApplicationBar.Buttons.Add(button); } } ColorListPicker.ItemsSource = App.ViewModel.Constants.Colors; ColorListPicker.DisplayMemberPath = "Name"; try { TaskStoreClientEntities.Color color = App.ViewModel.Constants.Colors.Single(c => c.Name == tagCopy.Color); ColorListPicker.SelectedIndex = App.ViewModel.Constants.Colors.IndexOf(color); } catch (Exception) { } //ColorListPicker.ItemCountThreshold = App.ViewModel.Constants.Colors.Count; }
// When page is navigated to set data context to selected item in listType protected override void OnNavigatedTo(NavigationEventArgs e) { // trace data TraceHelper.AddMessage("List: OnNavigatedTo"); string IDString = ""; string typeString = ""; Guid id; if (NavigationContext.QueryString.TryGetValue("type", out typeString) == false) { // trace page navigation TraceHelper.StartMessage("List: Navigate back"); // navigate back NavigationService.GoBack(); return; } switch (typeString) { case "TaskList": if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("List: Navigate back"); // navigate back NavigationService.GoBack(); return; } id = new Guid(IDString); // get the tasklist and make it the datacontext try { taskList = App.ViewModel.LoadList(id); // if the load failed, this list has been deleted if (taskList == null) { // the list isn't found - this can happen when the list we were just // editing was removed in TaskListEditor, which then goes back to TaskListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("List: Navigate back"); // navigate back NavigationService.GoBack(); return; } } catch (Exception ex) { // the list isn't found - this can happen when the list we were just // editing was removed in TaskListEditor, which then goes back to TaskListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage(String.Format("List: Navigate back (exception: {0})", ex.Message)); // navigate back NavigationService.GoBack(); return; } break; case "Tag": if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false) { // trace page navigation TraceHelper.StartMessage("List: Navigate back"); // navigate back NavigationService.GoBack(); return; } id = new Guid(IDString); // create a filter try { tag = App.ViewModel.Tags.Single(t => t.ID == id); taskList = new TaskList() { ID = Guid.Empty, Name = String.Format("tasks with {0} tag", tag.Name), Tasks = App.ViewModel.Tasks.Where(t => t.TaskTags.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 TagListEditor, which then goes back to TaskListPage. // this will send us back to the MainPage which is appropriate. // trace page navigation TraceHelper.StartMessage("List: Navigate back"); // navigate back NavigationService.GoBack(); return; } break; default: // trace page navigation TraceHelper.StartMessage("List: Navigate back"); // navigate back NavigationService.GoBack(); return; } // set datacontext DataContext = taskList; // create the TaskListHelper TaskListHelper = new TaskStoreWinPhone.TaskListHelper( taskList, new RoutedEventHandler(CompleteCheckbox_Click), new RoutedEventHandler(Tag_HyperlinkButton_Click)); // store the current listbox and ordering PivotItem item = (PivotItem) PivotControl.Items[PivotControl.SelectedIndex]; TaskListHelper.ListBox = (ListBox)((Grid)item.Content).Children[1]; TaskListHelper.OrderBy = (string)item.Header; // trace data TraceHelper.AddMessage("Exiting List OnNavigatedTo"); }
public Tag(Tag tag) { Copy(tag); }
public void Copy(Tag obj) { if (obj == null) return; // copy all of the properties foreach (PropertyInfo pi in this.GetType().GetProperties()) { var val = pi.GetValue(obj, null); pi.SetValue(this, val, null); } }