RowDefinition.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. namespace Avalonia.Controls
  4. {
  5. /// <summary>
  6. /// Holds a row definitions for a <see cref="Grid"/>.
  7. /// </summary>
  8. public class RowDefinition : DefinitionBase
  9. {
  10. /// <summary>
  11. /// Defines the <see cref="MaxHeight"/> property.
  12. /// </summary>
  13. public static readonly StyledProperty<double> MaxHeightProperty =
  14. AvaloniaProperty.Register<RowDefinition, double>(nameof(MaxHeight), double.PositiveInfinity);
  15. /// <summary>
  16. /// Defines the <see cref="MinHeight"/> property.
  17. /// </summary>
  18. public static readonly StyledProperty<double> MinHeightProperty =
  19. AvaloniaProperty.Register<RowDefinition, double>(nameof(MinHeight));
  20. /// <summary>
  21. /// Defines the <see cref="Height"/> property.
  22. /// </summary>
  23. public static readonly StyledProperty<GridLength> HeightProperty =
  24. AvaloniaProperty.Register<RowDefinition, GridLength>(nameof(Height), new GridLength(1, GridUnitType.Star));
  25. /// <summary>
  26. /// Initializes static members of the <see cref="RowDefinition"/> class.
  27. /// </summary>
  28. static RowDefinition()
  29. {
  30. AffectsParentMeasure(MaxHeightProperty, MinHeightProperty);
  31. HeightProperty.Changed.AddClassHandler<DefinitionBase>(OnUserSizePropertyChanged);
  32. }
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="RowDefinition"/> class.
  35. /// </summary>
  36. public RowDefinition()
  37. {
  38. }
  39. /// <summary>
  40. /// Initializes a new instance of the <see cref="RowDefinition"/> class.
  41. /// </summary>
  42. /// <param name="value">The height of the row.</param>
  43. /// <param name="type">The height unit of the column.</param>
  44. public RowDefinition(double value, GridUnitType type)
  45. {
  46. Height = new GridLength(value, type);
  47. }
  48. /// <summary>
  49. /// Initializes a new instance of the <see cref="RowDefinition"/> class.
  50. /// </summary>
  51. /// <param name="height">The height of the column.</param>
  52. public RowDefinition(GridLength height)
  53. {
  54. Height = height;
  55. }
  56. /// <summary>
  57. /// Gets the actual calculated height of the row.
  58. /// </summary>
  59. public double ActualHeight => Parent?.GetFinalRowDefinitionHeight(Index) ?? 0d;
  60. /// <summary>
  61. /// Gets or sets the maximum height of the row in DIPs.
  62. /// </summary>
  63. public double MaxHeight
  64. {
  65. get
  66. {
  67. return GetValue(MaxHeightProperty);
  68. }
  69. set
  70. {
  71. SetValue(MaxHeightProperty, value);
  72. }
  73. }
  74. /// <summary>
  75. /// Gets or sets the minimum height of the row in DIPs.
  76. /// </summary>
  77. public double MinHeight
  78. {
  79. get
  80. {
  81. return GetValue(MinHeightProperty);
  82. }
  83. set
  84. {
  85. SetValue(MinHeightProperty, value);
  86. }
  87. }
  88. /// <summary>
  89. /// Gets or sets the height of the row.
  90. /// </summary>
  91. public GridLength Height
  92. {
  93. get
  94. {
  95. return GetValue(HeightProperty);
  96. }
  97. set
  98. {
  99. SetValue(HeightProperty, value);
  100. }
  101. }
  102. internal override GridLength UserSizeValueCache => this.Height;
  103. internal override double UserMinSizeValueCache => this.MinHeight;
  104. internal override double UserMaxSizeValueCache => this.MaxHeight;
  105. }
  106. }