How to update an item from a group in sflistview(MVVM)?
I can only update, only when I reload the ItemsSource.
Could you show an example?
To update the items of the ListView , you enable the INotifyPropertyChanged for each item in the Model class to update the UI when you update the items. Please refer the below documentation for more reference.
UG Link: https://help.syncfusion.com/maui/listview/getting-started#creating-data-model-for-the-listview
Also If you want to update the items of the groups in SfListView, set the listView.DataSource.LiveDataUpdateMode to LiveDataUpdateMode.AllowDataShaping, which updates the runtime changes in the groups.Please refer the below ug for more information.
Grouping: https://help.syncfusion.com/maui/listview/grouping
Please let us know if you are facing the issue? If yes please share the exact requirement on updating the items of the Groups. Also we have attached the sample for Grouping and creating and binding the data to the listview.
Hi!
I made a change to the example they sent to demonstrate.
I added a button where the description changes on click but doesn't update!
Can you help me?
We have checked the provide sample, we would like let you that Button inside the GroupHeaderTemplate which have the binding context as the Group result , where the GroupResult contains Groups , Key , Items and IsExpand properties , as changes these properties will trigger the converter, which bound the binding context of the DataTrigger of button.Here you have achieve you requirement by setting the proper binding context and refreshing the datasource. we have attached the code snippet and modified sample for your reference and let us know if you still facing issue.
Code snippet:
Xaml page
<syncfusion:SfListView.GroupHeaderTemplate > <DataTemplate x:Name="GroupHeaderTemplate"> … <Button Text="Collect" TextTransform="None" Command="{Binding Path=BindingContext.ButtonCollectCommand, Source={x:Reference collectionsPage}, Mode=TwoWay}" CommandParameter="{Binding .}" Padding="0" HeightRequest="34" WidthRequest="120"> <Button.Triggers> <DataTrigger TargetType="Button" Binding="{Binding Path= BindingContext.Items,Source= {RelativeSource Self}, Converter={StaticResource ConverterCollecting}}" Value="True"> <Setter Property="IsEnabled" Value="False"/> <Setter Property="Text" Value="Collecting"/> <Setter Property="BackgroundColor" Value="IndianRed"/> </DataTrigger> </Button.Triggers> |
ViewModel.cs
public Command ButtonCollectCommand => new Command<object>((x) => OnButtonCollectClick(x)); private void OnButtonCollectClick(object obj) { GroupResultSelected = obj as GroupResult; var items = GroupResultSelected.Items.ToList<Model>().ToObservableCollection(); ExecuteCollectCommand(items).ConfigureAwait(true); GetData.Refresh(); } private async Task ExecuteCollectCommand(ObservableCollection<Model> pointview) { //Alternate True / False pointview[0].Group.Collecting = !pointview[0].Group.Collecting; } } |