How to use IListState with ItemSource-DataTemplates within MVUX correctly? #2392
|
Hi there, i think i'm missing something. For simplicity i used the Uno-Sample-App and added my code. Basically, what i have done: In my In the Where 'CustomRadioButton.xaml' is defined as: And finally the 'CustomRadioButtonModel.cs': That how I think it should work. The problem: What am I doing wrong? Also, when I define As workaround I'm using MVVM, but i want to stick to MVUX |
Replies: 2 comments 2 replies
|
Hey @AuderixDev thanks for the question. Actually we are not supporting "nested" bindable models. The idea is more to expose an immutable model and create a new instance of that model on each update (including for lists). You can get more info off the reason here: https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Mvux/WorkingWithRecords.html. In your case, I was about to recommend you to use the selection operator https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Mvux/Advanced/Selection.html, however I noticed that the First I created an immutable public class CustomRadioButtonEntity(string ButtonText);Then in you public IListState<CustomRadioButtonEntity> CustomRadioButtons => ListState<CustomRadioButtonEntity>.Value(this, () => [new("Custom Button 1"), new("Custom Button 2")]);
[Value] // This is to allow direct binding of a CustomRadioButtonEntity instead of de-normalizing it.
public IState<CustomRadioButtonEntity> SelectedCustomRadioButton => State<CustomRadioButtonEntity>.Empty(this);Finally in the <RadioButtons ItemsSource="{Binding CustomRadioButtons}" SelectedItem="{Binding SelectedCustomRadioButton, Mode=TwoWay}">Doing this you can now easily get the currently selected item from your model simply by |
|
Thank you for the detailed reply. And the ButtonCommand in the MainModel is now @dr1rrb edit: deleted long text about an error, which is already tracked here: #2383 |
Hey @AuderixDev thanks for the question.
Actually we are not supporting "nested" bindable models. The idea is more to expose an immutable model and create a new instance of that model on each update (including for lists). You can get more info off the reason here: https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Mvux/WorkingWithRecords.html.
In your case, I was about to recommend you to use the selection operator https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Mvux/Advanced/Selection.html, however I noticed that the
RadioButtonsdoes not supports theISelectionInfoon which we rely for this. So in your case I would simply use a 2-way binding on theS…