Hi. Sorry if my English is rough, Spanish is my native language.
- I'm using MVVM.
- I have a collection of items inside a listview and each one has 2 buttons.
- Button.Text property is variable. It is the result of a convertion based on a property of the collection item.
- Both buttons use the same command.
I want to update the collection item with the random Button.Text generated in the convertion. How can I do that?
// ============================= //Model.cs public class SomeClass { public string ItemType {get;set;} public string ButtonTextProperty {get;set;} } // ============================= // ============================= // ViewModel.cs public Command SomeCommand { get; set; } public ControlObjetosChecklistsViewModel() { this.SomeCommand = new Command(async (object param) => await someCommand (param)); } private async Task someCommand(object param) { // get the object by taking the button bindingcontext // get button text property // update object with that text property } // ============================= // ============================= //View.xaml <ListView x:Name="listView" ItemsSource="{Binding ItemSource}" SelectionMode="None" HasUnevenRows="True"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Button x:Name="btn1" Text="{Binding ItemType, Converter={StaticResource converter}, ConverterParameter=converterparameter1}" Command="{Binding Source={x:Reference listView}, Path=BindingContext.SomeCommand}" CommandParameter="{Binding .}" HorizontalOptions="FillAndExpand"/> <Button x:Name="btn2" Text="{Binding ItemType, Converter={StaticResource converter}, ConverterParameter=converterparameter2}" Command="{Binding Source={x:Reference listView}, Path=BindingContext.SomeCommand}" CommandParameter="{Binding .}" HorizontalOptions="FillAndExpand"/> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> // =============================