|
public class GroupItemConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var label = parameter as Label;
var items=(value as IEnumerable).ToList<Contacts>().ToList();
label.Text = (items[0] as Contacts).Complete;
return label;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
|
<listView:SfListView x:Name="listView" AutoFitMode="Height" GroupHeaderSize="60"
ItemsSource="{Binding contactsinfo}" ItemSpacing="0,0,5,0">
<listView:SfListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout BackgroundColor="#E4E4E4">
<Label Text="{Binding Key}"
FontSize="22"
FontAttributes="Bold"
VerticalOptions="Center"
HorizontalOptions="Start"
Margin="20,0,0,0" />
<Label x:Name="GroupHeaderLabel" BindingContext="{Binding Items, Converter={StaticResource GroupItemConverter}, ConverterParameter={x:Reference GroupHeaderLabel}}"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</listView:SfListView.GroupHeaderTemplate> </listView:SfListView> |
|
private void Button_Clicked(object sender, EventArgs e)
{
(listView.DataSource.DisplayItems[1] as Contacts).Complete = "Incomplete";
listView.DataSource.Refresh();
} |
Hello,
Where would a viable location be for adding listView.DataSource.Refresh(); in the code examples above?
Thanks,
Wynston
Hi Wynston,
You can use the DataSource.Refresh method in the method that you use to update the property mentioned in this update.
Additionally, whenever the underlying object data changes during runtime, the DataSource.SourcePropertyChanged event is triggered. In this event, you can invoke the Refresh method.
You can also refer to the following documentation to update the GroupHeader based on its items data at run time,
Please let us know if you need further assistance.
Regards,
Lakshmi Natarajan
Hi Lakshmi,
Is there way to update the property on the label of the GroupHeaderTemplate without refreshing the list? For example, I am using the converter example provided above, but if I update the property inside the ViewModel, can that be reflected on the Label inside the GroupHeaderTemplate as well?
Thanks,
Wynston
Hi Wynston,
The converter will be triggered when the binding property is updated. We update the underlying object data, in this case, but the converter binding value is Items from the GroupResult rather than the underlying object. As a result, the converter is unaware of the data changes and must be forced to trigger by calling the refresh method. This is expected behaviour in Xamairn.Forms.
Note: The GroupResult is the BindingContext for the GroupHeaderTemplate.
You can also refer to our user guidance document regarding the group header customization in the following link,
UG link: https://help.syncfusion.com/xamarin/listview/grouping#group-header-customization
Please let us know if you need further assistance.
Regards,
Lakshmi Natarajan
Hi Lakshmi,
Thank you for that explanation. That clears things a bit.
For the refreshing the list, where in the code solution (provided to the original creator of this post), whether that's in the page's code-behind or a converter, can I add a listView.DataSource.Refresh()?
Thanks,
Wynston
Hi Wynston,
As we have mentioned in our previous updates, you can call the Refresh method in the code behind where you update the underlying object.
Please let us know if you need further assistance.
Lakshmi Natarajan