The ExpandGroups and CollapseGroups methods in SfListView
allow you to programmatically expand and collapse the group. Accessing XAML
controls from ViewModel is not recommended because it violates the MVVM rule.
You can meet your requirements by using MessagingCenter in Xamarin.Forms.
Publish an expand message in which group you need to expand by
passing it as the third parameter in the Send method of MessagingCenter, as
shown in the code snippet below.
Code Snippet:
//ViewModel.cs
private void TappedCommandMethod(object obj)
{
MessagingCenter.Send<BookInfoRepository,int>(this, "Expand",0);
}
|
Using MessagingCenter, subscribe to a message that contains
group information. in the ListView behavior and pass that group detail to
the ExpandGroup method, as shown in the code snippet below.
//ListViewBehavior.cs
protected override void OnAttachedTo(SfListView bindable)
{
MessagingCenter.Subscribe<BookInfoRepository,
int>(this, "Expand", async (sender, arg)
=>
{
var
group = bindable.DataSource.Groups[arg];
bindable.ExpandGroup(group);
});
base.OnAttachedTo(bindable);
}
|
Please refer to our user guidelines documentation regarding
programmatic expanding and collapsing in the below link.
UG link: https://help.syncfusion.com/xamarin/listview/grouping#programmatic-expand-and-collapse
And, also refer MessagingCenter in Xamarin.Forms in the
below reference link.
Reference link: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center
We have attached a runnable based on your requirement for
your reference. Please let us know if you need any further assistance.
Attachment:
GettingStarted_834ffb84.zip