-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomControl.cs
38 lines (35 loc) · 1.23 KB
/
CustomControl.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
namespace BindableProperty_validation
{
public class CustomControl : ContentView
{
public static readonly BindableProperty CustomTextProperty = BindableProperty.Create(
nameof(CustomText),
typeof(string),
typeof(CustomControl),
defaultValue: string.Empty,
validateValue: (bindable, value) =>
{
// This validator returns false for empty strings
// We expect this to throw an ArgumentException, but it doesn't
return !string.IsNullOrEmpty((string)value);
}
);
public string CustomText
{
get => (string)GetValue(CustomTextProperty);
set => SetValue(CustomTextProperty, value);
}
public CustomControl()
{
// Basic layout for demonstration
Content = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
};
CustomText = "some valid text";
// Set up the binding correctly
((Label)Content).SetBinding(Label.TextProperty, new Binding(nameof(CustomText), source: this));
}
}
}