5
5
using Windows . UI ;
6
6
using Uno . Disposables ;
7
7
using System . Windows . Input ;
8
+ using Uno . Extensions ;
9
+ using Microsoft . Extensions . Logging ;
8
10
9
11
#if WinUI
10
12
using Microsoft . UI . Xaml ;
@@ -66,94 +68,105 @@ public static class ControlExtensions
66
68
#endregion
67
69
68
70
#region DependencyProperty: LeadingIcon
69
-
70
71
public static DependencyProperty LeadingIconProperty { [ DynamicDependency ( nameof ( GetLeadingIcon ) ) ] get ; } = DependencyProperty . RegisterAttached (
71
72
"LeadingIcon" ,
72
73
typeof ( IconElement ) ,
73
74
typeof ( ControlExtensions ) ,
74
- new PropertyMetadata ( default ) ) ;
75
+ new PropertyMetadata ( default , OnLeadingIconChanged ) ) ;
75
76
76
77
[ DynamicDependency ( nameof ( SetLeadingIcon ) ) ]
77
78
public static IconElement GetLeadingIcon ( Control obj ) => ( IconElement ) obj . GetValue ( LeadingIconProperty ) ;
78
79
79
80
[ DynamicDependency ( nameof ( GetLeadingIcon ) ) ]
80
81
public static void SetLeadingIcon ( Control obj , IconElement value ) => obj . SetValue ( LeadingIconProperty , value ) ;
81
82
83
+ private static void OnLeadingIconChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
84
+ => WarnNotSupportedProperty ( d , "LeadingIcon" ) ;
82
85
#endregion
83
86
84
87
#region DependencyProperty: IsLeadingIconVisible
85
-
86
88
public static DependencyProperty IsLeadingIconVisibleProperty { [ DynamicDependency ( nameof ( GetIsLeadingIconVisible ) ) ] get ; } = DependencyProperty . RegisterAttached (
87
89
"IsLeadingIconVisible" ,
88
90
typeof ( bool ) ,
89
91
typeof ( ControlExtensions ) ,
90
- new PropertyMetadata ( true ) ) ;
92
+ new PropertyMetadata ( true , OnIsLeadingIconVisibleChanged ) ) ;
91
93
92
94
[ DynamicDependency ( nameof ( SetIsLeadingIconVisible ) ) ]
93
95
public static bool GetIsLeadingIconVisible ( Control obj ) => ( bool ) obj . GetValue ( IsLeadingIconVisibleProperty ) ;
94
96
95
97
[ DynamicDependency ( nameof ( GetIsLeadingIconVisible ) ) ]
96
98
public static void SetIsLeadingIconVisible ( Control obj , bool value ) => obj . SetValue ( IsLeadingIconVisibleProperty , value ) ;
97
99
100
+ private static void OnIsLeadingIconVisibleChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
101
+ => WarnNotSupportedProperty ( d , "IsLeadingIconVisible" ) ;
98
102
#endregion
99
103
100
104
#region DependencyProperty: LeadingCommand
101
105
public static DependencyProperty LeadingCommandProperty { [ DynamicDependency ( nameof ( GetLeadingCommand ) ) ] get ; } = DependencyProperty . RegisterAttached (
102
106
"LeadingCommand" ,
103
107
typeof ( ICommand ) ,
104
108
typeof ( ControlExtensions ) ,
105
- new PropertyMetadata ( default ) ) ;
109
+ new PropertyMetadata ( default , OnLeadingCommandChanged ) ) ;
106
110
107
111
[ DynamicDependency ( nameof ( GetLeadingCommand ) ) ]
108
112
public static ICommand GetLeadingCommand ( Control obj ) => ( ICommand ) obj . GetValue ( LeadingCommandProperty ) ;
109
113
110
114
[ DynamicDependency ( nameof ( SetLeadingCommand ) ) ]
111
115
public static void SetLeadingCommand ( Control obj , ICommand value ) => obj . SetValue ( LeadingCommandProperty , value ) ;
116
+
117
+ private static void OnLeadingCommandChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
118
+ => WarnNotSupportedProperty ( d , "LeadingCommand" ) ;
112
119
#endregion
113
120
114
121
#region DependencyProperty: TrailingIcon
115
-
116
122
public static DependencyProperty TrailingIconProperty { [ DynamicDependency ( nameof ( GetTrailingIcon ) ) ] get ; } = DependencyProperty . RegisterAttached (
117
123
"TrailingIcon" ,
118
124
typeof ( IconElement ) ,
119
125
typeof ( ControlExtensions ) ,
120
- new PropertyMetadata ( default ) ) ;
126
+ new PropertyMetadata ( default , OnTrailingIconChanged ) ) ;
121
127
122
128
[ DynamicDependency ( nameof ( SetTrailingIcon ) ) ]
123
129
public static IconElement GetTrailingIcon ( Control obj ) => ( IconElement ) obj . GetValue ( TrailingIconProperty ) ;
124
130
125
131
[ DynamicDependency ( nameof ( GetTrailingIcon ) ) ]
126
132
public static void SetTrailingIcon ( Control obj , IconElement value ) => obj . SetValue ( TrailingIconProperty , value ) ;
133
+
134
+ private static void OnTrailingIconChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
135
+ => WarnNotSupportedProperty ( d , "TrailingIcon" ) ;
127
136
#endregion
128
137
129
138
#region DependencyProperty: IsTrailingIconVisible
130
-
131
139
public static DependencyProperty IsTrailingIconVisibleProperty { [ DynamicDependency ( nameof ( GetIsTrailingIconVisible ) ) ] get ; } = DependencyProperty . RegisterAttached (
132
140
"IsTrailingIconVisible" ,
133
141
typeof ( bool ) ,
134
142
typeof ( ControlExtensions ) ,
135
- new PropertyMetadata ( true ) ) ;
143
+ new PropertyMetadata ( true , OnIsTrailingIconVisibleChanged ) ) ;
136
144
137
145
[ DynamicDependency ( nameof ( SetIsTrailingIconVisible ) ) ]
138
146
public static bool GetIsTrailingIconVisible ( Control obj ) => ( bool ) obj . GetValue ( IsTrailingIconVisibleProperty ) ;
139
147
140
148
[ DynamicDependency ( nameof ( GetIsTrailingIconVisible ) ) ]
141
149
public static void SetIsTrailingIconVisible ( Control obj , bool value ) => obj . SetValue ( IsTrailingIconVisibleProperty , value ) ;
142
150
151
+ private static void OnIsTrailingIconVisibleChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
152
+ => WarnNotSupportedProperty ( d , "IsTrailingIconVisible" ) ;
143
153
#endregion
144
154
145
155
#region DependencyProperty: TrailingCommand
146
156
public static DependencyProperty TrailingCommandProperty { [ DynamicDependency ( nameof ( GetTrailingCommand ) ) ] get ; } = DependencyProperty . RegisterAttached (
147
157
"TrailingCommand" ,
148
158
typeof ( ICommand ) ,
149
159
typeof ( ControlExtensions ) ,
150
- new PropertyMetadata ( default ) ) ;
160
+ new PropertyMetadata ( default , OnTrailingCommandChanged ) ) ;
151
161
152
162
[ DynamicDependency ( nameof ( GetTrailingCommand ) ) ]
153
163
public static ICommand GetTrailingCommand ( Control obj ) => ( ICommand ) obj . GetValue ( TrailingCommandProperty ) ;
154
164
155
165
[ DynamicDependency ( nameof ( SetTrailingCommand ) ) ]
156
166
public static void SetTrailingCommand ( Control obj , ICommand value ) => obj . SetValue ( TrailingCommandProperty , value ) ;
167
+
168
+ private static void OnTrailingCommandChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
169
+ => WarnNotSupportedProperty ( d , "TrailingCommand" ) ;
157
170
#endregion
158
171
159
172
#region DependencyProperty: AlternateContent
@@ -205,6 +218,7 @@ public static class ControlExtensions
205
218
public static void SetTintedBackground ( UIElement obj , SolidColorBrush value ) => obj . SetValue ( TintedBackgroundProperty , value ) ;
206
219
207
220
#endregion
221
+
208
222
#region DependencyProperty: IsTintEnabled
209
223
/// <summary>
210
224
/// Gets or sets whether or not the SurfaceTintColor should be applied for elevated views
@@ -230,6 +244,14 @@ private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedE
230
244
}
231
245
}
232
246
247
+ private static void WarnNotSupportedProperty ( DependencyObject d , string propertyName )
248
+ {
249
+ if ( d is not TextBox )
250
+ {
251
+ d . Log ( ) . LogWarning ( $ "Warning: { propertyName } is only supported on TextBox controls.") ;
252
+ }
253
+ }
254
+
233
255
private static void OnElevationChanged ( DependencyObject element , DependencyPropertyChangedEventArgs e )
234
256
=> SurfaceTintExtensions . OnElevationChanged ( element , ( int ) e . NewValue ) ;
235
257
0 commit comments