Closed NiX3r closed 3 months ago
Both of you @TerminatedGA and @rphmauriciodev are reported 💪
This is an experimental feature and we'll improve the usage, but for now it uses reflection, you can add some configuration to use different components:
MauiProgram.cs
builder.Services.Configure<AutoFormViewOptions>(options =>
{
options.EditorMapping[typeof(string)] = (property, propertyNameFactory, source) =>
{
var propertyName = propertyNameFactory(property);
var dataTypeAttribute = property.GetCustomAttribute<DataTypeAttribute>();
if (dataTypeAttribute != null && dataTypeAttribute.DataType == DataType.MultilineText)
{
var textArea = new EditorField();
textArea.SetBinding(EditorField.TextProperty, new Binding(property.Name, source: source));
textArea.Title = propertyName;
return textArea;
}
var editor = new TextField();
editor.Title = propertyName;
editor.SetBinding(TextField.TextProperty, new Binding(property.Name, source: source));
return editor;
};
});
I'll enhance this experience, but currently you can configure it manually according to your requirements
This is an experimental feature and we'll improve the usage, but for now it uses reflection, you can add some configuration to use different components:
MauiProgram.cs
builder.Services.Configure<AutoFormViewOptions>(options => { options.EditorMapping[typeof(string)] = (property, propertyNameFactory, source) => { var propertyName = propertyNameFactory(property); var dataTypeAttribute = property.GetCustomAttribute<DataTypeAttribute>(); if (dataTypeAttribute != null && dataTypeAttribute.DataType == DataType.MultilineText) { var textArea = new EditorField(); textArea.SetBinding(EditorField.TextProperty, new Binding(propertyName, source: source)); textArea.Title = propertyName; } var editor = new TextField(); editor.Title = propertyName; editor.SetBinding(TextField.TextProperty, new Binding(property.Name, source: source)); return editor; }; });
I'll enhance this experience, but currently you can configure it manually according to your requirements
Hey .. that works. But I have to append return textArea
in if statemnet
And what about that Discord? Or is it pasé?
Yeah, I gorgot to add return, my bad. 😀 I wrote it in github editor instead IDE.
And what about that Discord? Or is it pasé?
I answered your email, that would be nice 🎉
One more thing
I needed change this line
textArea.SetBinding(EditorField.TextProperty, new Binding(propertyName, source: source));
Change propertyName
to propert.Name
because the binding won't work well 💪
Final working code:
builder.Services.Configure<AutoFormViewOptions>(options =>
{
options.EditorMapping[typeof(string)] = (property, propertyNameFactory, source) =>
{
var propertyName = propertyNameFactory(property);
var dataTypeAttribute = property.GetCustomAttribute<DataTypeAttribute>();
if (dataTypeAttribute != null && dataTypeAttribute.DataType == DataType.MultilineText)
{
var textArea = new EditorField();
textArea.Title = propertyName;
textArea.SetBinding(EditorField.TextProperty, new Binding(property.Name, source: source));
return textArea;
}
var editor = new TextField();
editor.Title = propertyName;
editor.SetBinding(TextField.TextProperty, new Binding(property.Name, source: source));
return editor;
};
});
Thanks 🙏 I updated the first example again 👍
Hey there 👋 I'm just curious if there is some attribute to set input as editor? I need to be
Description
as editor (need to be visually multiline and can input new lines)I've got this. But
DataType
does not seems work ..And this is how I'm calling it
And lastly .. I sent u email, but I will try this way either. Can I build Discord server for you for your projects? I think it will be much easier to help with issues and communicate with your community 💪