-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
SemanticProperties.cs
56 lines (44 loc) · 1.73 KB
/
SemanticProperties.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
using System;
namespace Microsoft.Maui.Controls
{
public class SemanticProperties
{
public static readonly BindableProperty DescriptionProperty = BindableProperty.CreateAttached("Description", typeof(string), typeof(SemanticProperties), default(string), propertyChanged : OnHintPropertyChanged);
public static readonly BindableProperty HintProperty = BindableProperty.CreateAttached("Hint", typeof(string), typeof(SemanticProperties), default(string), propertyChanged: OnDescriptionPropertyChanged);
static void OnDescriptionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
SetupSemanticsProperty(bindable)
.Description = SemanticProperties.GetHint(bindable);
UpdateSemanticsProperty(bindable);
}
static void OnHintPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
SetupSemanticsProperty(bindable)
.Hint = SemanticProperties.GetHint(bindable);
UpdateSemanticsProperty(bindable);
}
static Semantics SetupSemanticsProperty(BindableObject bindable) =>
((VisualElement)bindable).SetupSemantics();
static void UpdateSemanticsProperty(BindableObject bindable)
{
if (bindable is IFrameworkElement fe)
fe.Handler?.UpdateValue(nameof(IView.Semantics));
}
public static string GetDescription(BindableObject bindable)
{
return (string)bindable.GetValue(DescriptionProperty);
}
public static void SetDescription(BindableObject bindable, string value)
{
bindable.SetValue(DescriptionProperty, value);
}
public static string GetHint(BindableObject bindable)
{
return (string)bindable.GetValue(HintProperty);
}
public static void SetHint(BindableObject bindable, string value)
{
bindable.SetValue(HintProperty, value);
}
}
}