WidthSupport.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:WidthSupport
  3. * 作者:xulisong
  4. * 创建时间: 2019/5/29 14:24:11
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. namespace FWindSoft.Wpf.Controls
  15. {
  16. /// <summary>
  17. /// 宽度支撑
  18. /// </summary>
  19. public class WidthSupport:Border
  20. {
  21. public WidthSupport()
  22. {
  23. this.Visibility = Visibility.Hidden;
  24. this.HorizontalAlignment = HorizontalAlignment.Stretch;
  25. }
  26. public static readonly DependencyProperty MarkerProperty =
  27. DependencyProperty.Register("SupportElement", typeof(FrameworkElement), typeof(WidthSupport));
  28. /// <summary>
  29. /// 所支撑的元素
  30. /// </summary>
  31. public FrameworkElement SupportElement
  32. {
  33. get { return (FrameworkElement)GetValue(MarkerProperty); }
  34. set { SetValue(MarkerProperty, value); }
  35. }
  36. protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
  37. {
  38. //基类是程序集级别的,也能重写?
  39. if (SupportElement != null)
  40. {
  41. (SupportElement).Width = this.ActualWidth;
  42. SupportElement.UpdateLayout();
  43. }
  44. }
  45. }
  46. }