EdgeElement.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Windows;
  2. using HandyControl.Data;
  3. namespace HandyControl.Controls;
  4. public class EdgeElement
  5. {
  6. public static readonly DependencyProperty LeftContentProperty = DependencyProperty.RegisterAttached(
  7. "LeftContent", typeof(object), typeof(EdgeElement), new PropertyMetadata(default(object), OnEdgeContentChanged));
  8. public static void SetLeftContent(DependencyObject element, object value) => element.SetValue(LeftContentProperty, value);
  9. public static object GetLeftContent(DependencyObject element) => element.GetValue(LeftContentProperty);
  10. public static readonly DependencyProperty TopContentProperty = DependencyProperty.RegisterAttached(
  11. "TopContent", typeof(object), typeof(EdgeElement), new PropertyMetadata(default(object), OnEdgeContentChanged));
  12. public static void SetTopContent(DependencyObject element, object value) => element.SetValue(TopContentProperty, value);
  13. public static object GetTopContent(DependencyObject element) => element.GetValue(TopContentProperty);
  14. public static readonly DependencyProperty RightContentProperty = DependencyProperty.RegisterAttached(
  15. "RightContent", typeof(object), typeof(EdgeElement), new PropertyMetadata(default(object), OnEdgeContentChanged));
  16. public static void SetRightContent(DependencyObject element, object value) => element.SetValue(RightContentProperty, value);
  17. public static object GetRightContent(DependencyObject element) => element.GetValue(RightContentProperty);
  18. public static readonly DependencyProperty BottomContentProperty = DependencyProperty.RegisterAttached(
  19. "BottomContent", typeof(object), typeof(EdgeElement), new PropertyMetadata(default(object), OnEdgeContentChanged));
  20. public static void SetBottomContent(DependencyObject element, object value) => element.SetValue(BottomContentProperty, value);
  21. public static object GetBottomContent(DependencyObject element) => element.GetValue(BottomContentProperty);
  22. public static readonly DependencyProperty ShowEdgeContentProperty = DependencyProperty.RegisterAttached(
  23. "ShowEdgeContent", typeof(bool), typeof(EdgeElement), new PropertyMetadata(ValueBoxes.FalseBox));
  24. public static void SetShowEdgeContent(DependencyObject element, bool value) => element.SetValue(ShowEdgeContentProperty, ValueBoxes.BooleanBox(value));
  25. public static bool GetShowEdgeContent(DependencyObject element) => (bool) element.GetValue(ShowEdgeContentProperty);
  26. private static void OnEdgeContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
  27. SetShowEdgeContent(d, !(GetLeftContent(d) == null && GetTopContent(d) == null &&
  28. GetRightContent(d) == null && GetBottomContent(d) == null));
  29. }