0
My Xamarin application has as one of its features, creating forms based on an object.
I have been having trouble saving the data from this form. I have to go through the children of Stacklayout to then popular the Dictionary<string, object>()
.
What I would like to do (and I believe it is the right way to do it) is to use Xamarin’s databiding to link the form elements with the Dictionary<string, object>()
this way avoid that I need to go through the list of elements every time.
As the form is created dynamically, I would not do Biding by XAML, but rather at some point I create the view:
var entry = new
Keyboard = Keyboard.Numeric,
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.CenterAndExpand
};
I just don’t know if I add the Dictionary I have in my Viewmodel.
Yes. Either you add the Dictionary to the view model or you feed some other class (which you would still have to create) to work with the reported values.
– Diego Rafael Souza
The chunk of code is incomplete, but I understand that you are creating a
Entry
. Make the entry bind with each element of your dictionary, I believe will solve your problem.– Diego Rafael Souza
The dictionary would already need to have the correct keys so that the bind knows where to store the information from
Entry
?– Liberi
Yes. The bind will be made for a dictionary element, not for the entire dictionary. Type, if you have
Dictionary<string, object> dic = new Dictionary<string, object>();
Binding context for each component would bedic["key"]
for example.– Diego Rafael Souza
Diego, that answer right here is exactly what I wanted to do. https://stackoverflow.com/questions/36985634/xamarin-forms-databinding-separator Thanks for the help
– Liberi
Great! The bad thing is that in XAML you have to leave indexes/keys hardcoded, but if it’s not a problem, beauty.
– Diego Rafael Souza