DynamicKanbanColumn.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. namespace InABox.DynamicGrid
  6. {
  7. public delegate void KanbanColumnCollapsedHandler(object sender, bool collapsed);
  8. /// <summary>
  9. /// Interaction logic for KanbanColumn.xaml
  10. /// </summary>
  11. public partial class DynamicKanbanColumn : UserControl
  12. {
  13. public static readonly DependencyProperty TitleProperty =
  14. DependencyProperty.Register("Title", typeof(string), typeof(DynamicKanbanColumn));
  15. public static readonly DependencyProperty CollapsedProperty =
  16. DependencyProperty.Register("Collapsed", typeof(bool), typeof(DynamicKanbanColumn));
  17. public static readonly DependencyProperty HeaderContextMenuProperty =
  18. DependencyProperty.Register("HeaderContextMenu", typeof(ContextMenu), typeof(DynamicKanbanColumn));
  19. public static readonly DependencyProperty ItemTemplateProperty =
  20. DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(DynamicKanbanColumn));
  21. public static readonly DependencyProperty ItemContextMenuProperty =
  22. DependencyProperty.Register("ItemContextMenu", typeof(ContextMenu), typeof(DynamicKanbanColumn));
  23. public static readonly DependencyProperty ItemsSourceProperty =
  24. DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(DynamicKanbanColumn));
  25. private bool _collapsed;
  26. public DynamicKanbanColumn()
  27. {
  28. InitializeComponent();
  29. }
  30. public string Title
  31. {
  32. get => (string)GetValue(TitleProperty);
  33. set
  34. {
  35. ColumnTitle.Content = value;
  36. SetValue(TitleProperty, value);
  37. }
  38. }
  39. public bool Collapsed
  40. {
  41. get => (bool)GetValue(CollapsedProperty);
  42. set
  43. {
  44. _collapsed = value;
  45. ColumnGrid.ColumnDefinitions[0].Width = value ? new GridLength(0, GridUnitType.Pixel) : new GridLength(1, GridUnitType.Star);
  46. ColumnGrid.ColumnDefinitions[1].Width = value ? new GridLength(1, GridUnitType.Auto) : new GridLength(0, GridUnitType.Pixel);
  47. MinWidth = _collapsed ? 35.0F : 300.0F;
  48. OnCollapsed?.Invoke(this, value);
  49. SetValue(CollapsedProperty, value);
  50. }
  51. }
  52. public ContextMenu HeaderContextMenu
  53. {
  54. get => (ContextMenu)GetValue(HeaderContextMenuProperty);
  55. set => SetValue(HeaderContextMenuProperty, value);
  56. }
  57. public DataTemplate ItemTemplate
  58. {
  59. get => (DataTemplate)GetValue(ItemTemplateProperty);
  60. set => SetValue(ItemTemplateProperty, value);
  61. }
  62. public ContextMenu ItemContextMenu
  63. {
  64. get => (ContextMenu)GetValue(ItemContextMenuProperty);
  65. set => SetValue(ItemContextMenuProperty, value);
  66. }
  67. public IEnumerable ItemsSource
  68. {
  69. get => (IEnumerable)GetValue(ItemsSourceProperty);
  70. set => SetValue(ItemsSourceProperty, value);
  71. }
  72. public event KanbanColumnCollapsedHandler OnCollapsed;
  73. private void ExpandColumn_Click(object sender, MouseButtonEventArgs e)
  74. {
  75. Collapsed = false;
  76. }
  77. private void CollapseColumn_Click(object sender, MouseButtonEventArgs e)
  78. {
  79. Collapsed = true;
  80. }
  81. }
  82. }