GanttSetupBehaviour.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using Microsoft.Xaml.Behaviors;
  4. using Syncfusion.Windows.Controls.Gantt;
  5. using Syncfusion.Windows.Controls.Gantt.Chart;
  6. using Syncfusion.Windows.Controls.Grid;
  7. using DependencyObjectExtensions = Syncfusion.Windows.Controls.Gantt.DependencyObjectExtensions;
  8. namespace PRSDesktop
  9. {
  10. public class GanttSetupBehaviour : Behavior<GanttControl>
  11. {
  12. /// <summary>
  13. /// Called when [attached].
  14. /// </summary>
  15. protected override void OnAttached()
  16. {
  17. AssociatedObject.Loaded += AssociatedObject_Loaded;
  18. }
  19. /// <summary>
  20. /// Handles the Loaded event of the AssociatedObject control.
  21. /// </summary>
  22. /// <param name="sender">The source of the event.</param>
  23. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
  24. private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
  25. {
  26. if (AssociatedObject.GanttGrid != null) AssociatedObject.GanttGrid.UpdateMode = UpdateMode.PropertyChanged;
  27. var chart = DependencyObjectExtensions.FindName<GanttChart>(AssociatedObject, "PART_GanttChart");
  28. if (chart != null)
  29. {
  30. var chartScrollViewer =
  31. DependencyObjectExtensions.FindName<ScrollViewer>(chart, "PART_GanttChartScrollViewer");
  32. if (chartScrollViewer != null)
  33. {
  34. // To make the GanttChart's Vertical Scroll bar visible.
  35. chartScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
  36. chartScrollViewer.ScrollChanged += ChartScrollViewer_ScrollChanged;
  37. }
  38. }
  39. }
  40. private void ChartScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
  41. {
  42. // To sync the GanttGrid's vertical scroll with GanttChart's Vertical scroll offset.
  43. AssociatedObject.GanttGrid.InternalGrid.SetVerticalOffset(e.VerticalOffset);
  44. }
  45. /// <summary>
  46. /// Called when [detaching].
  47. /// </summary>
  48. protected override void OnDetaching()
  49. {
  50. AssociatedObject.Loaded -= AssociatedObject_Loaded;
  51. }
  52. }
  53. }