示例#1
0
        private void ApplicationBarIconDeleteButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you really want to delete this exercise?", "7Drum", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                ExerciseSettings ex = (ExerciseSettings)lbExercise.SelectedItem;
                (Application.Current as App).Exercises.Remove(ex);

                // Refresh ListBox items
                lbExercise.ItemsSource = null;
                lbExercise.ItemsSource = (Application.Current as App).Exercises.OrderBy(o => o.Name);
            }
        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.NavigationContext.QueryString.ContainsKey("Id"))
            {
                Guid id = new Guid(this.NavigationContext.QueryString["Id"]);

                ExerciseSettings exercise = (from ex in (Application.Current as App).Exercises
                                             where ex.id == id
                                             select ex).SingleOrDefault <ExerciseSettings>();

                txtName.Text        = exercise.Name;
                txtDuration.Text    = exercise.Duration.ToString();
                txtDescription.Text = exercise.Description;
            }
        }
        private void ApplicationBarIconSaveButton_Click(object sender, EventArgs e)
        {
            bool bNew = true;

            if (this.NavigationContext.QueryString.ContainsKey("Id"))
            {
                bNew = false;
            }
            else
            {
                bNew = true;
            }

            if (txtName.Text != string.Empty && txtDuration.Text != string.Empty)
            {
                ExerciseSettings exercise = null;

                if (!bNew)
                {
                    exercise = (from ex in (Application.Current as App).Exercises
                                where ex.id == new Guid(this.NavigationContext.QueryString["Id"])
                                select ex).SingleOrDefault <ExerciseSettings>();
                }
                else
                {
                    exercise    = new ExerciseSettings();
                    exercise.id = Guid.NewGuid();
                }

                exercise.Description = txtDescription.Text;
                exercise.Name        = txtName.Text;
                exercise.Duration    = int.Parse(txtDuration.Text);

                if (bNew)
                {
                    (Application.Current as App).Exercises.Add(exercise);
                }

                Clean();
            }
            else
            {
                MessageBox.Show("Name and duration fields are mandatory.", "7Drum", MessageBoxButton.OK);
            }
        }