ColumnDefinition.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 column definitions for a <see cref="Grid"/>.
  7. /// </summary>
  8. public class ColumnDefinition : DefinitionBase
  9. {
  10. /// <summary>
  11. /// Defines the <see cref="MaxWidth"/> property.
  12. /// </summary>
  13. public static readonly StyledProperty<double> MaxWidthProperty =
  14. AvaloniaProperty.Register<ColumnDefinition, double>(nameof(MaxWidth), double.PositiveInfinity);
  15. /// <summary>
  16. /// Defines the <see cref="MinWidth"/> property.
  17. /// </summary>
  18. public static readonly StyledProperty<double> MinWidthProperty =
  19. AvaloniaProperty.Register<ColumnDefinition, double>(nameof(MinWidth));
  20. /// <summary>
  21. /// Defines the <see cref="Width"/> property.
  22. /// </summary>
  23. public static readonly StyledProperty<GridLength> WidthProperty =
  24. AvaloniaProperty.Register<ColumnDefinition, GridLength>(nameof(Width), new GridLength(1, GridUnitType.Star));
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref="ColumnDefinition"/> class.
  27. /// </summary>
  28. public ColumnDefinition()
  29. {
  30. }
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="ColumnDefinition"/> class.
  33. /// </summary>
  34. /// <param name="value">The width of the column.</param>
  35. /// <param name="type">The width unit of the column.</param>
  36. public ColumnDefinition(double value, GridUnitType type)
  37. {
  38. Width = new GridLength(value, type);
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="ColumnDefinition"/> class.
  42. /// </summary>
  43. /// <param name="width">The width of the column.</param>
  44. public ColumnDefinition(GridLength width)
  45. {
  46. Width = width;
  47. }
  48. /// <summary>
  49. /// Gets the actual calculated width of the column.
  50. /// </summary>
  51. public double ActualWidth
  52. {
  53. get;
  54. internal set;
  55. }
  56. /// <summary>
  57. /// Gets or sets the maximum width of the column in DIPs.
  58. /// </summary>
  59. public double MaxWidth
  60. {
  61. get { return GetValue(MaxWidthProperty); }
  62. set { SetValue(MaxWidthProperty, value); }
  63. }
  64. /// <summary>
  65. /// Gets or sets the minimum width of the column in DIPs.
  66. /// </summary>
  67. public double MinWidth
  68. {
  69. get { return GetValue(MinWidthProperty); }
  70. set { SetValue(MinWidthProperty, value); }
  71. }
  72. /// <summary>
  73. /// Gets or sets the width of the column.
  74. /// </summary>
  75. public GridLength Width
  76. {
  77. get { return GetValue(WidthProperty); }
  78. set { SetValue(WidthProperty, value); }
  79. }
  80. }
  81. }