FormHeader.xaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace InABox.DynamicGrid
  16. {
  17. /// <summary>
  18. /// Interaction logic for FormHeader.xaml
  19. /// </summary>
  20. public partial class FormHeader : UserControl
  21. {
  22. public delegate void CollapsedChangedEvent(FormHeader header, bool collapsed);
  23. public static readonly DependencyProperty HeaderTextProperty = DependencyProperty.Register("HeaderText", typeof(string), typeof(FormHeader));
  24. public static readonly DependencyProperty CollapsedProperty = DependencyProperty.Register(
  25. "Collapsed", typeof(bool), typeof(FormHeader),
  26. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.None, new PropertyChangedCallback(OnCollapsedChanged)));
  27. public static readonly DependencyProperty TextDecorationsProperty = DependencyProperty.Register("TextDecorations", typeof(TextDecorationCollection), typeof(FormHeader));
  28. public string HeaderText
  29. {
  30. get => GetValue(HeaderTextProperty).ToString() ?? "";
  31. set => SetValue(HeaderTextProperty, value);
  32. }
  33. public bool Collapsed
  34. {
  35. get => (bool)GetValue(CollapsedProperty);
  36. set => SetValue(CollapsedProperty, value);
  37. }
  38. public TextDecorationCollection TextDecorations
  39. {
  40. get => TextBlock.TextDecorations;
  41. set => TextBlock.TextDecorations = value;
  42. }
  43. public event CollapsedChangedEvent? CollapsedChanged;
  44. public FormHeader()
  45. {
  46. InitializeComponent();
  47. }
  48. private static void OnCollapsedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  49. {
  50. var header = (FormHeader)d;
  51. var collapsed = (bool)e.NewValue;
  52. header.CollapsedChanged?.Invoke(header, collapsed);
  53. }
  54. private void Button_Click(object sender, RoutedEventArgs e)
  55. {
  56. Collapsed = !Collapsed;
  57. }
  58. }
  59. }