1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
@@ -29,15 +29,10 @@ public bool CanTrigger
29
29
nameof ( CanTrigger ) ,
30
30
typeof ( bool ) ,
31
31
typeof ( ControlWidthTrigger ) ,
32
- new PropertyMetadata ( true , OnCanTriggerProperty ) ) ;
33
-
34
- private static void OnCanTriggerProperty ( DependencyObject d , DependencyPropertyChangedEventArgs e )
35
- {
36
- ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ;
37
- }
32
+ new PropertyMetadata ( true , ( d , e ) => ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ) ) ;
38
33
39
34
/// <summary>
40
- /// Gets or sets the max size at which to trigger.
35
+ /// Gets or sets the max width at which to trigger.
41
36
/// </summary>
42
37
public double MaxWidth
43
38
{
@@ -52,15 +47,10 @@ public double MaxWidth
52
47
nameof ( MaxWidth ) ,
53
48
typeof ( double ) ,
54
49
typeof ( ControlWidthTrigger ) ,
55
- new PropertyMetadata ( double . PositiveInfinity , OnMaxWidthPropertyChanged ) ) ;
56
-
57
- private static void OnMaxWidthPropertyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
58
- {
59
- ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ;
60
- }
50
+ new PropertyMetadata ( double . PositiveInfinity , ( d , e ) => ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ) ) ;
61
51
62
52
/// <summary>
63
- /// Gets or sets the min size at which to trigger.
53
+ /// Gets or sets the min width at which to trigger.
64
54
/// </summary>
65
55
public double MinWidth
66
56
{
@@ -75,13 +65,44 @@ public double MinWidth
75
65
nameof ( MinWidth ) ,
76
66
typeof ( double ) ,
77
67
typeof ( ControlWidthTrigger ) ,
78
- new PropertyMetadata ( 0.0 , OnMinWidthPropertyChanged ) ) ;
68
+ new PropertyMetadata ( 0.0 , ( d , e ) => ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ) ) ;
79
69
80
- private static void OnMinWidthPropertyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
70
+ /// <summary>
71
+ /// Gets or sets the max height at which to trigger.
72
+ /// </summary>
73
+ public double MaxHeight
81
74
{
82
- ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ;
75
+ get => ( double ) GetValue ( MaxHeightProperty ) ;
76
+ set => SetValue ( MaxHeightProperty , value ) ;
83
77
}
84
78
79
+ /// <summary>
80
+ /// Identifies the <see cref="MaxHeight"/> DependencyProperty.
81
+ /// </summary>
82
+ public static readonly DependencyProperty MaxHeightProperty = DependencyProperty . Register (
83
+ nameof ( MaxHeight ) ,
84
+ typeof ( double ) ,
85
+ typeof ( ControlWidthTrigger ) ,
86
+ new PropertyMetadata ( double . PositiveInfinity , ( d , e ) => ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ) ) ;
87
+
88
+ /// <summary>
89
+ /// Gets or sets the min height at which to trigger.
90
+ /// </summary>
91
+ public double MinHeight
92
+ {
93
+ get => ( double ) GetValue ( MinHeightProperty ) ;
94
+ set => SetValue ( MinHeightProperty , value ) ;
95
+ }
96
+
97
+ /// <summary>
98
+ /// Identifies the <see cref="MinHeight"/> DependencyProperty.
99
+ /// </summary>
100
+ public static readonly DependencyProperty MinHeightProperty = DependencyProperty . Register (
101
+ nameof ( MinHeight ) ,
102
+ typeof ( double ) ,
103
+ typeof ( ControlWidthTrigger ) ,
104
+ new PropertyMetadata ( 0.0 , ( d , e ) => ( ( ControlWidthTrigger ) d ) . UpdateTrigger ( ) ) ) ;
105
+
85
106
/// <summary>
86
107
/// Gets or sets the element whose width will observed
87
108
/// for the trigger.
@@ -139,7 +160,11 @@ private void UpdateTrigger()
139
160
return ;
140
161
}
141
162
142
- SetActive ( MinWidth <= TargetElement . ActualWidth && TargetElement . ActualWidth < MaxWidth ) ;
163
+ SetActive (
164
+ MinWidth <= TargetElement . ActualWidth &&
165
+ TargetElement . ActualWidth < MaxWidth &&
166
+ MinHeight <= TargetElement . ActualHeight &&
167
+ TargetElement . ActualHeight < MaxHeight ) ;
143
168
}
144
169
}
145
170
}
0 commit comments