-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
VisualElement.cs
424 lines (377 loc) · 18.2 KB
/
VisualElement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#nullable disable
namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific
{
using System;
using Microsoft.Maui.Graphics;
using FormsElement = Maui.Controls.VisualElement;
/// <summary>
/// Provides access to the blur effect, shadow effect, and legacy color mode on the iOS platform.
/// </summary>
public static class VisualElement
{
/// <summary>Bindable property for attached property <c>BlurEffect</c>.</summary>
public static readonly BindableProperty BlurEffectProperty = BindableProperty.Create("BlurEffect", typeof(BlurEffectStyle), typeof(VisualElement), BlurEffectStyle.None);
/// <summary>
/// Returns a value that controls which, if any, blur effect is applied.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns>A value that controls which, if any, blur effect is applied.</returns>
public static BlurEffectStyle GetBlurEffect(BindableObject element)
{
return (BlurEffectStyle)element.GetValue(BlurEffectProperty);
}
/// <summary>
/// Sets a value that controls which, if any, blur effect is applied.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value">The new property value to assign.</param>
public static void SetBlurEffect(BindableObject element, BlurEffectStyle value)
{
element.SetValue(BlurEffectProperty, value);
}
/// <summary>
/// Returns a value that controls which, if any, blur effect is applied.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns>A value that controls which, if any, blur effect is applied.</returns>
public static BlurEffectStyle GetBlurEffect(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetBlurEffect(config.Element);
}
/// <summary>
/// Sets the blur effect to use.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value">The new property value to assign.</param>
/// <returns>The updated configuration object on which developers can make successive method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> UseBlurEffect(this IPlatformElementConfiguration<iOS, FormsElement> config, BlurEffectStyle value)
{
SetBlurEffect(config.Element, value);
return config;
}
#region Shadow Settings
/// <summary>
/// Represents a shadow effect that can be applied to iOS controls.
/// </summary>
public class ShadowEffect : RoutingEffect
{
public ShadowEffect() : base("Microsoft.Maui.Controls.ShadowEffect") { }
}
/// <summary>Bindable property for attached property <c>IsShadowEnabled</c>.</summary>
public static readonly BindableProperty IsShadowEnabledProperty =
BindableProperty.Create("IsShadowEnabled", typeof(bool),
typeof(VisualElement), false, propertyChanged: OnIsShadowEnabledChanged);
static void OnIsShadowEnabledChanged(BindableObject bindable, object oldValue, object newValue)
{
var visualElement = bindable as FormsElement;
var enabled = (bool)newValue;
if (enabled)
{
visualElement.Effects.Add(new ShadowEffect());
}
else
{
foreach (var effect in visualElement.Effects)
{
if (effect is ShadowEffect)
{
visualElement.Effects.Remove(effect);
break;
}
}
}
}
/// <summary>
/// Gets whether or not the shadow effect is enabled.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns><see langword="true" /> if the shadow effect is enabled. Otherwise, <see langword="false" />.</returns>
public static bool GetIsShadowEnabled(BindableObject element)
{
return (bool)element.GetValue(IsShadowEnabledProperty);
}
/// <summary>
/// Sets whether or not the shadow effect is enabled.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value"><see langword="true" /> to enable the shadow. Otherwise, <see langword="false" />.</param>
public static void SetIsShadowEnabled(BindableObject element, bool value)
{
element.SetValue(IsShadowEnabledProperty, value);
}
/// <summary>
/// Gets whether or not the shadow effect is enabled.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns><see langword="true" /> if the shadow effect is enabled. Otherwise, <see langword="false" />.</returns>
public static bool GetIsShadowEnabled(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetIsShadowEnabled(config.Element);
}
/// <summary>
/// Sets whether or not the shadow effect is enabled.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value"><see langword="true" /> to enable the shadow. Otherwise, <see langword="false" />.</param>
/// <returns>A fluent object on which the developer may make more method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetIsShadowEnabled(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
{
SetIsShadowEnabled(config.Element, value);
return config;
}
/// <summary>Bindable property for attached property <c>ShadowColor</c>.</summary>
public static readonly BindableProperty ShadowColorProperty =
BindableProperty.Create("ShadowColor", typeof(Color),
typeof(VisualElement), null);
/// <summary>
/// Gets the current shadow color.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns>The current shadow color.</returns>
public static Color GetShadowColor(BindableObject element)
{
return (Color)element.GetValue(ShadowColorProperty);
}
/// <summary>
/// Sets the shadow color.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value">The new shadow color value.</param>
public static void SetShadowColor(BindableObject element, Color value)
{
element.SetValue(ShadowColorProperty, value);
}
/// <summary>
/// Gets the current shadow color.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns>The current shadow color.</returns>
public static Color GetShadowColor(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetShadowColor(config.Element);
}
/// <summary>
/// Sets the shadow color.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value">The new shadow color value.</param>
/// <returns>A fluent object on which the developer may make further method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetShadowColor(this IPlatformElementConfiguration<iOS, FormsElement> config, Color value)
{
SetShadowColor(config.Element, value);
return config;
}
/// <summary>Bindable property for attached property <c>ShadowRadius</c>.</summary>
public static readonly BindableProperty ShadowRadiusProperty =
BindableProperty.Create("ShadowRadius", typeof(double),
typeof(VisualElement), 10.0);
/// <summary>
/// Gets the current shadow radius.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns>The current shadow radius.</returns>
public static double GetShadowRadius(BindableObject element)
{
return (double)element.GetValue(ShadowRadiusProperty);
}
/// <summary>
/// Sets the shadow radius.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value">The new shadow radius value.</param>
public static void SetShadowRadius(BindableObject element, double value)
{
element.SetValue(ShadowRadiusProperty, value);
}
/// <summary>
/// Gets the current shadow radius.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns>The current shadow radius.</returns>
public static double GetShadowRadius(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetShadowRadius(config.Element);
}
/// <summary>
/// Sets the shadow radius.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value">The new shadow radius value.</param>
/// <returns>A fluent object on which the developer may make further method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetShadowRadius(this IPlatformElementConfiguration<iOS, FormsElement> config, double value)
{
SetShadowRadius(config.Element, value);
return config;
}
/// <summary>Bindable property for attached property <c>ShadowOffset</c>.</summary>
public static readonly BindableProperty ShadowOffsetProperty =
BindableProperty.Create("ShadowOffset", typeof(Size),
typeof(VisualElement), Size.Zero);
/// <summary>
/// Gets the current shadow offset.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns>The current shadow offset.</returns>
public static Size GetShadowOffset(BindableObject element)
{
return (Size)element.GetValue(ShadowOffsetProperty);
}
/// <summary>
/// Sets the shadow offset.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value">The new shadow offset value.</param>
public static void SetShadowOffset(BindableObject element, Size value)
{
element.SetValue(ShadowOffsetProperty, value);
}
/// <summary>
/// Gets the current shadow offset.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns>The current shadow offset.</returns>
public static Size GetShadowOffset(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetShadowOffset(config.Element);
}
/// <summary>
/// Sets the shadow offset.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value">The new shadow offset value.</param>
/// <returns>A fluent object on which the developer may make further method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetShadowOffset(this IPlatformElementConfiguration<iOS, FormsElement> config, Size value)
{
SetShadowOffset(config.Element, value);
return config;
}
/// <summary>Bindable property for attached property <c>ShadowOpacity</c>.</summary>
public static readonly BindableProperty ShadowOpacityProperty =
BindableProperty.Create("ShadowOpacity", typeof(double),
typeof(VisualElement), 0.5);
/// <summary>
/// Gets the current shadow opacity.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns>The current shadow opacity.</returns>
public static double GetShadowOpacity(BindableObject element)
{
return (double)element.GetValue(ShadowOpacityProperty);
}
/// <summary>
/// Sets the shadow opacity.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value">The new shadow opacity value.</param>
public static void SetShadowOpacity(BindableObject element, double value)
{
element.SetValue(ShadowOpacityProperty, value);
}
/// <summary>
/// The shadow opacity.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns>The current shadow opacity.</returns>
public static double GetShadowOpacity(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetShadowOpacity(config.Element);
}
/// <summary>
/// Sets the shadow opacity.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value">The new shadow opacity value.</param>
/// <returns>A fluent object on which the developer may make further method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetShadowOpacity(this IPlatformElementConfiguration<iOS, FormsElement> config, double value)
{
SetShadowOpacity(config.Element, value);
return config;
}
#endregion
#region IsLegacyColorModeEnabled
/// <summary>Bindable property for attached property <c>IsLegacyColorModeEnabled</c>.</summary>
public static readonly BindableProperty IsLegacyColorModeEnabledProperty =
BindableProperty.CreateAttached("IsLegacyColorModeEnabled", typeof(bool),
typeof(FormsElement), true);
/// <summary>
/// Returns whether or not the legacy color mode is enabled.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns><see langword="true" /> if the legacy color mode is enabled. Otherwise, <see langword="false" />.</returns>
public static bool GetIsLegacyColorModeEnabled(BindableObject element)
{
return (bool)element.GetValue(IsLegacyColorModeEnabledProperty);
}
/// <summary>
/// Sets whether the legacy color mode is enabled.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value"><see langword="true" /> to enable legacy color mode. Otherwise, <see langword="false" />.</param>
public static void SetIsLegacyColorModeEnabled(BindableObject element, bool value)
{
element.SetValue(IsLegacyColorModeEnabledProperty, value);
}
/// <summary>
/// Returns whether or not the legacy color mode is enabled.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns><see langword="true" /> if the legacy color mode is enabled. Otherwise, <see langword="false" />.</returns>
public static bool GetIsLegacyColorModeEnabled(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return (bool)config.Element.GetValue(IsLegacyColorModeEnabledProperty);
}
/// <summary>
/// Sets whether the legacy color mode is enabled.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value"><see langword="true" /> to enable legacy color mode. Otherwise, <see langword="false" />.</param>
/// <returns>A fluent object on which the developer may make further method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetIsLegacyColorModeEnabled(
this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
{
config.Element.SetValue(IsLegacyColorModeEnabledProperty, value);
return config;
}
#endregion
/// <summary>Bindable property for <see cref="CanBecomeFirstResponder"/>.</summary>
public static readonly BindableProperty CanBecomeFirstResponderProperty = BindableProperty.Create(nameof(CanBecomeFirstResponder), typeof(bool), typeof(VisualElement), false);
/// <summary>
/// Gets whether this element can become the first responder to touch events, rather than the page containing the element.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <returns><see langword="true" /> when this element can become first responder. Otherwise, <see langword="false" />.</returns>
public static bool GetCanBecomeFirstResponder(BindableObject element)
{
return (bool)element.GetValue(CanBecomeFirstResponderProperty);
}
/// <summary>
/// Sets whether this element can become the first responder to touch events, rather than the page containing the element.
/// </summary>
/// <param name="element">The platform specific element on which to perform the operation.</param>
/// <param name="value"><see langword="true" /> to set this element as the first responder. Otherwise, <see langword="false" />.</param>
public static void SetCanBecomeFirstResponder(BindableObject element, bool value)
{
element.SetValue(CanBecomeFirstResponderProperty, value);
}
/// <summary>
/// Gets whether this element can become the first responder to touch events, rather than the page containing the element.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <returns><see langword="true" /> when this element can become first responder. Otherwise, <see langword="false" />.</returns>
public static bool CanBecomeFirstResponder(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetCanBecomeFirstResponder(config.Element);
}
/// <summary>
/// Sets whether this element can become the first responder to touch events, rather than the page containing the element.
/// </summary>
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
/// <param name="value"><see langword="true" /> to set this element as the first responder. Otherwise, <see langword="false" />.</param>
/// <returns>A fluent object on which the developer may make further method calls.</returns>
public static IPlatformElementConfiguration<iOS, FormsElement> SetCanBecomeFirstResponder(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
{
SetCanBecomeFirstResponder(config.Element, value);
return config;
}
}
}