Creating custom Controls (Is there a better way?) #1183
-
When creating a For instance (in the Code-Behind): public partial class ProfileDetailView: ContentView
{
public static readonly BindableProperty EmailProperty =
BindableProperty.Create(nameof(Email), typeof(string), typeof(LoginView), string.Empty);
public string Email
{
get => (string)GetValue(EmailProperty);
set => SetValue(EmailProperty, value);
}
[...]
} Seems, to me, incredibly verbose when compared to what is available in [ObservableProperty]
private string _email = string.Empty; I understand these are different paradigms for different use-cases, but is there a way to generate the above ( public partial class ProfileDetailView: ContentView
{
[BindableProperty]
private string _email = string.Empty;
// Auto-generate:
// |- public static readonly BindableProperty EmailProperty
// \- propertyName: Email
// \- returnType: typeof(string)
// \- declaringType: typeof(ProfileDetailView)
// \- defaultValue: string.Empty (?? this I am dubious/unsure of ??)
// |- public string Email
// \- getter (cast GetValue of EmailProperty)
// \- setter (SetValue for EmailProperty using value)
[...]
} Does this already exist perhaps? (If so, would someone be so kind as to direct me to that documentation? I didn't see it, but perhaps I don't know the right term for it!) Many thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
There're nuget packages that do it for you, we have an open spec for that but isn't started yet. |
Beta Was this translation helpful? Give feedback.
-
Closed as answered |
Beta Was this translation helpful? Give feedback.
@MDale-RAC the spec is the potential design for it, for people to discuess how it should be implemented before someone starts to work on it - #542
There are existing nuget packages that you could use, such as - https://github.com/rrmanzano/maui-bindableproperty-generator