private void CopyButton_Click(object sender, RoutedEventArgs e)
 {
     if (ScheduleChartDataGrid.GetSelectedItemCount() <= 0)
     {
         MessageBox.Show("Cannot copy selected item(s) as the selection is empty; select an item first.", "Information", MessageBoxButton.OK);
         return;
     }
     ScheduleChartDataGrid.Copy();
 }
 private void RedoButton_Click(object sender, RoutedEventArgs e)
 {
     if (ScheduleChartDataGrid.CanRedo())
     {
         ScheduleChartDataGrid.Redo();
     }
     else
     {
         MessageBox.Show("Currently there is no recorded action in the redo queue; perform an action and undo it first.", "Information", MessageBoxButton.OK);
     }
 }
        // Control area commands.
        private void AddNewButton_Click(object sender, RoutedEventArgs e)
        {
            ScheduleChartItem item = new ScheduleChartItem {
                Content = "New Resource"
            };

            item.GanttChartItems.Add(new GanttChartItem {
                Content = "New Task", Start = DateTime.Today, Finish = DateTime.Today.AddDays(1)
            });
            ScheduleChartDataGrid.Items.Add(item);
            ScheduleChartDataGrid.SelectedItem = item;
            ScheduleChartDataGrid.ScrollTo(item.GanttChartItems[0]);
        }
        private void ScheduleChartDataGrid_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Point controlPosition = e.GetPosition(ScheduleChartDataGrid);
            Point contentPosition = e.GetPosition(ScheduleChartDataGrid.ChartContentElement);

            DateTime          dateTime = ScheduleChartDataGrid.GetDateTime(contentPosition.X);
            ScheduleChartItem itemRow  = ScheduleChartDataGrid.GetItemAt(contentPosition.Y);

            GanttChartItem   item             = null;
            FrameworkElement frameworkElement = e.OriginalSource as FrameworkElement;

            if (frameworkElement != null)
            {
                item = frameworkElement.DataContext as GanttChartItem;
            }

            if (controlPosition.X < ScheduleChartDataGrid.ActualWidth - ScheduleChartDataGrid.GanttChartView.ActualWidth)
            {
                return;
            }
            string message = String.Empty;

            if (controlPosition.Y < ScheduleChartDataGrid.HeaderHeight)
            {
                message = string.Format("You have clicked the chart scale header at date and time {0:g}.", dateTime);
            }
            else if (item != null)
            {
                message = string.Format("You have clicked the task item '{0}' assigned to resource item '{1}' at date and time {2:g}.", item, itemRow, dateTime > item.Finish ? item.Finish : dateTime);
            }
            else if (itemRow != null)
            {
                message = string.Format("You have clicked at date and time {0:g} within the row of item '{1}'.", dateTime, itemRow);
            }
            else
            {
                message = string.Format("You have clicked at date and time {0:g} within an empty area of the chart.", dateTime);
            }

            NotificationsTextBox.AppendText(string.Format("{0}{1}", NotificationsTextBox.Text.Length > 0 ? "\n" : string.Empty, message));
            NotificationsTextBox.ScrollToEnd();
        }
 private void ExportImageButton_Click(object sender, RoutedEventArgs e)
 {
     ScheduleChartDataGrid.Export((Action) delegate
     {
         SaveFileDialog saveFileDialog = new SaveFileDialog {
             Title = "Export Image To", Filter = "PNG image files|*.png"
         };
         if (saveFileDialog.ShowDialog() != true)
         {
             return;
         }
         BitmapSource bitmapSource = ScheduleChartDataGrid.GetExportBitmapSource(96 * 2);
         using (Stream stream = saveFileDialog.OpenFile())
         {
             PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
             pngBitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapSource));
             pngBitmapEncoder.Save(stream);
         }
     });
 }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            List <ScheduleChartItem> items = new List <ScheduleChartItem>();

            foreach (ScheduleChartItem item in ScheduleChartDataGrid.GetSelectedItems())
            {
                items.Add(item);
            }
            if (items.Count <= 0)
            {
                MessageBox.Show("Cannot delete the selected item(s) as the selection is empty; select an item first.", "Information", MessageBoxButton.OK);
                return;
            }
            items.Reverse();
            // ScheduleChartDataGrid.BeginInit();
            foreach (ScheduleChartItem item in items)
            {
                ScheduleChartDataGrid.Items.Remove(item);
            }
            // ScheduleChartDataGrid.EndInit();
        }
        private void SetColorButton_Click(object sender, RoutedEventArgs e)
        {
            List <ScheduleChartItem> items = new List <ScheduleChartItem>();

            foreach (ScheduleChartItem item in ScheduleChartDataGrid.GetSelectedItems())
            {
                items.Add(item);
            }
            if (items.Count <= 0)
            {
                MessageBox.Show("Cannot set a custom bar color to the selected item(s) as the selection is empty; select an item first.", "Information", MessageBoxButton.OK);
                return;
            }
            foreach (ScheduleChartItem item in items)
            {
                foreach (GanttChartItem ganttChartItem in item.GanttChartItems)
                {
                    GanttChartView.SetStandardBarFill(ganttChartItem, Resources["CustomStandardBarFill"] as Brush);
                    GanttChartView.SetStandardBarStroke(ganttChartItem, Resources["CustomStandardBarStroke"] as Brush);
                }
            }
        }
 private void PrintButton_Click(object sender, RoutedEventArgs e)
 {
     ScheduleChartDataGrid.Print("ScheduleChartDataGrid Sample Document");
 }
 private void PasteButton_Click(object sender, RoutedEventArgs e)
 {
     ScheduleChartDataGrid.Paste();
 }