Ejemplo n.º 1
0
        private void TaskListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listView = sender as TasksListView;
            var vm       = (TasksPageViewModel)DataContext;

            if (_selectionInProgress)
            {
                return;
            }

            try
            {
                //if nothing is selected
                if (listView.SelectedIndex == -1)
                {
                    vm.TaskListViewSelectedItemCommand.Execute(null);
                    return;
                }

                _selectionInProgress = true;

                var navVm = Frame.DataContext as NavPageViewModel;

                var parent      = ((Frame.Parent as Border).Parent as Grid).Parent as Grid;
                var newTaskPage = MiscellaneousUtils.FindControl <Grid>(parent, "MainSplitViewPane");
                var newTaskVm   = newTaskPage.DataContext as NewTaskPageViewModel;

                if (navVm.IsPaneOpen &&
                    newTaskVm.AppSettings.AskBeforeDiscardChanges &&
                    newTaskVm.ChangesWereMade())
                {
                    vm.DesiredTaskIndex    = listView.SelectedIndex;
                    listView.SelectedIndex = _lastSelectedIndex;
                    newTaskVm.ClosePaneCommand.Execute(null);
                    return;
                }

                _lastSelectedIndex = listView.SelectedIndex;

                vm.TaskListViewSelectedItemCommand.Execute(listView.SelectedItem);
            }
            catch (Exception)
            {
            }
            finally
            {
                _selectionInProgress = false;
            }
        }