예제 #1
0
        private void Label_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            MainWindowViewModel mainWindowViewModel = this.DataContext as MainWindowViewModel;
            Label       label       = sender as Label;
            Appointment appointment = label.DataContext as Appointment;

            DetailsWindow          detailsWindow          = new DetailsWindow();
            DetailsWindowViewModel detailsWindowViewModel = detailsWindow.DataContext as DetailsWindowViewModel;

            detailsWindowViewModel.Appointment = appointment;
            bool?res = detailsWindow.ShowDialog();

            if (res.HasValue && res.Value)
            {
                Appointment newAppointment = detailsWindowViewModel.Appointment;
                if (newAppointment != null)
                {
                    try
                    {
                        mainWindowViewModel.EditAppointment(appointment, detailsWindowViewModel.Appointment);
                    }
                    catch (ConcurrentUpdateException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    mainWindowViewModel.DeleteAppointment(appointment);
                }
            }
        }
예제 #2
0
        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                MainWindowViewModel mainWindowViewModel = this.DataContext as MainWindowViewModel;
                StackPanel          stackPanel          = sender as StackPanel;
                Day day = stackPanel.DataContext as Day;
                Console.WriteLine(day.DateTime);

                DetailsWindow          detailsWindow          = new DetailsWindow();
                DetailsWindowViewModel detailsWindowViewModel = detailsWindow.DataContext as DetailsWindowViewModel;
                detailsWindowViewModel.Day = day;
                bool?res = detailsWindow.ShowDialog();
                if (res.HasValue && res.Value)
                {
                    Appointment newAppointment = detailsWindowViewModel.Appointment;
                    if (newAppointment != null)
                    {
                        mainWindowViewModel.AddAppointment(day, detailsWindowViewModel.Appointment);
                    }
                }
            }
        }