FormHeader.xaml.cs 2.3 KB

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