Ejemplo n.º 1
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            TraceHelper.AddMessage("Main: Loaded");

            // if data isn't loaded from storage yet, load the app data
            if (!App.ViewModel.IsDataLoaded)
            {
                // Load app data from local storage (user creds, about tab data, constants, list types, tasklists, etc)
                App.ViewModel.LoadData();
            }

            // if haven't synced with web service yet, try now
            if (initialSync == false)
            {
                // attempt to sync with the Service
                App.ViewModel.SyncWithService();

                initialSync = true;
            }

            taskList = new TaskList() { Tasks = FilterTasks(App.ViewModel.Tasks) };

            // create the TaskListHelper
            TaskListHelper = new TaskStoreWinPhone.TaskListHelper(
                taskList,
                new RoutedEventHandler(Tasks_CompleteCheckbox_Click),
                new RoutedEventHandler(Tag_HyperlinkButton_Click));

            // store the current listbox and ordering
            TaskListHelper.ListBox = TasksListBox;
            TaskListHelper.OrderBy = "due";

            // render the tasks
            TaskListHelper.RenderList(taskList);

            // add a property changed handler for the Tasks property
            if (!addedTasksPropertyChangedHandler)
            {
                App.ViewModel.PropertyChanged += new PropertyChangedEventHandler((s, args) =>
                {
                    // if the Tasks property was signaled, re-filter and re-render the tasks list
                    if (args.PropertyName == "Tasks")
                    {
                        taskList.Tasks = FilterTasks(App.ViewModel.Tasks);
                        TaskListHelper.RenderList(taskList);
                    }
                });
                addedTasksPropertyChangedHandler = true;
            }

            // set the datacontext
            SearchHeader.DataContext = this;

            // trace exit
            TraceHelper.AddMessage("Exiting Main Loaded");
        }
Ejemplo n.º 2
0
        // 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");
        }