AdaptiveClassSetter.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using Avalonia.Controls;
  2. using Avalonia.Metadata;
  3. using Avalonia.Xaml.Interactivity;
  4. namespace Avalonia.Xaml.Interactions.Responsive;
  5. /// <summary>
  6. /// Conditional class setter used in <see cref="AdaptiveBehavior"/> behavior.
  7. /// </summary>
  8. public class AdaptiveClassSetter : AvaloniaObject
  9. {
  10. /// <summary>
  11. /// Identifies the <seealso cref="MinWidth"/> avalonia property.
  12. /// </summary>
  13. public static readonly StyledProperty<double> MinWidthProperty =
  14. AvaloniaProperty.Register<AdaptiveClassSetter, double>(nameof(MinWidth));
  15. /// <summary>
  16. /// Identifies the <seealso cref="MinWidthOperator"/> avalonia property.
  17. /// </summary>
  18. public static readonly StyledProperty<ComparisonConditionType> MinWidthOperatorProperty =
  19. AvaloniaProperty.Register<AdaptiveClassSetter, ComparisonConditionType>(nameof(MinWidthOperator), ComparisonConditionType.GreaterThanOrEqual);
  20. /// <summary>
  21. /// Identifies the <seealso cref="MaxWidth"/> avalonia property.
  22. /// </summary>
  23. public static readonly StyledProperty<double> MaxWidthProperty =
  24. AvaloniaProperty.Register<AdaptiveClassSetter, double>(nameof(MaxWidth), double.PositiveInfinity);
  25. /// <summary>
  26. /// Identifies the <seealso cref="MaxWidthOperator"/> avalonia property.
  27. /// </summary>
  28. public static readonly StyledProperty<ComparisonConditionType> MaxWidthOperatorProperty =
  29. AvaloniaProperty.Register<AdaptiveClassSetter, ComparisonConditionType>(nameof(MaxWidthOperator), ComparisonConditionType.LessThan);
  30. /// <summary>
  31. /// Identifies the <seealso cref="MinHeight"/> avalonia property.
  32. /// </summary>
  33. public static readonly StyledProperty<double> MinHeightProperty =
  34. AvaloniaProperty.Register<AdaptiveClassSetter, double>(nameof(MinHeight));
  35. /// <summary>
  36. /// Identifies the <seealso cref="MinHeightOperator"/> avalonia property.
  37. /// </summary>
  38. public static readonly StyledProperty<ComparisonConditionType> MinHeightOperatorProperty =
  39. AvaloniaProperty.Register<AdaptiveClassSetter, ComparisonConditionType>(nameof(MinHeightOperator), ComparisonConditionType.GreaterThanOrEqual);
  40. /// <summary>
  41. /// Identifies the <seealso cref="MaxHeight"/> avalonia property.
  42. /// </summary>
  43. public static readonly StyledProperty<double> MaxHeightProperty =
  44. AvaloniaProperty.Register<AdaptiveClassSetter, double>(nameof(MaxHeight), double.PositiveInfinity);
  45. /// <summary>
  46. /// Identifies the <seealso cref="MaxHeightOperator"/> avalonia property.
  47. /// </summary>
  48. public static readonly StyledProperty<ComparisonConditionType> MaxHeightOperatorProperty =
  49. AvaloniaProperty.Register<AdaptiveClassSetter, ComparisonConditionType>(nameof(MaxHeightOperator), ComparisonConditionType.LessThan);
  50. /// <summary>
  51. /// Identifies the <seealso cref="ClassName"/> avalonia property.
  52. /// </summary>
  53. public static readonly StyledProperty<string?> ClassNameProperty =
  54. AvaloniaProperty.Register<AdaptiveClassSetter, string?>(nameof(ClassName));
  55. /// <summary>
  56. /// Identifies the <seealso cref="IsPseudoClass"/> avalonia property.
  57. /// </summary>
  58. public static readonly StyledProperty<bool> IsPseudoClassProperty =
  59. AvaloniaProperty.Register<AdaptiveClassSetter, bool>(nameof(IsPseudoClass));
  60. /// <summary>
  61. /// Identifies the <seealso cref="TargetControl"/> avalonia property.
  62. /// </summary>
  63. public static readonly StyledProperty<Control?> TargetControlProperty =
  64. AvaloniaProperty.Register<AdaptiveClassSetter, Control?>(nameof(TargetControl));
  65. /// <summary>
  66. /// Gets or sets minimum bounds width value used for property comparison. This is a avalonia property.
  67. /// </summary>
  68. public double MinWidth
  69. {
  70. get => GetValue(MinWidthProperty);
  71. set => SetValue(MinWidthProperty, value);
  72. }
  73. /// <summary>
  74. /// Gets or sets minimum bounds width value comparison operator. This is a avalonia property.
  75. /// </summary>
  76. public ComparisonConditionType MinWidthOperator
  77. {
  78. get => GetValue(MinWidthOperatorProperty);
  79. set => SetValue(MinWidthOperatorProperty, value);
  80. }
  81. /// <summary>
  82. /// Gets or sets maximum width value used for property comparison. This is a avalonia property.
  83. /// </summary>
  84. public double MaxWidth
  85. {
  86. get => GetValue(MaxWidthProperty);
  87. set => SetValue(MaxWidthProperty, value);
  88. }
  89. /// <summary>
  90. /// Gets or sets maximum bounds width value comparison operator. This is a avalonia property.
  91. /// </summary>
  92. public ComparisonConditionType MaxWidthOperator
  93. {
  94. get => GetValue(MaxWidthOperatorProperty);
  95. set => SetValue(MaxWidthOperatorProperty, value);
  96. }
  97. /// <summary>
  98. /// Gets or sets minimum bounds height value used for property comparison. This is a avalonia property.
  99. /// </summary>
  100. public double MinHeight
  101. {
  102. get => GetValue(MinHeightProperty);
  103. set => SetValue(MinHeightProperty, value);
  104. }
  105. /// <summary>
  106. /// Gets or sets minimum bounds height value comparison operator. This is a avalonia property.
  107. /// </summary>
  108. public ComparisonConditionType MinHeightOperator
  109. {
  110. get => GetValue(MinHeightOperatorProperty);
  111. set => SetValue(MinHeightOperatorProperty, value);
  112. }
  113. /// <summary>
  114. /// Gets or sets maximum height value used for property comparison. This is a avalonia property.
  115. /// </summary>
  116. public double MaxHeight
  117. {
  118. get => GetValue(MaxHeightProperty);
  119. set => SetValue(MaxHeightProperty, value);
  120. }
  121. /// <summary>
  122. /// Gets or sets maximum bounds height value comparison operator. This is a avalonia property.
  123. /// </summary>
  124. public ComparisonConditionType MaxHeightOperator
  125. {
  126. get => GetValue(MaxHeightOperatorProperty);
  127. set => SetValue(MaxHeightOperatorProperty, value);
  128. }
  129. /// <summary>
  130. /// Gets or sets the class name that should be added or removed. This is a avalonia property.
  131. /// </summary>
  132. [Content]
  133. public string? ClassName
  134. {
  135. get => GetValue(ClassNameProperty);
  136. set => SetValue(ClassNameProperty, value);
  137. }
  138. /// <summary>
  139. /// Gets or sets the flag whether ClassName is a PseudoClass. This is a avalonia property.
  140. /// </summary>
  141. public bool IsPseudoClass
  142. {
  143. get => GetValue(IsPseudoClassProperty);
  144. set => SetValue(IsPseudoClassProperty, value);
  145. }
  146. /// <summary>
  147. /// Gets or sets the target control that class name that should be added or removed when triggered, if not set <see cref="StyledElementBehavior{T}.AssociatedObject"/> is used or <see cref="AdaptiveBehavior.TargetControl"/> from <see cref="AdaptiveBehavior"/>. This is a avalonia property.
  148. /// </summary>
  149. [ResolveByName]
  150. public Control? TargetControl
  151. {
  152. get => GetValue(TargetControlProperty);
  153. set => SetValue(TargetControlProperty, value);
  154. }
  155. }