We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to do Datasource binding on xaml with mvvm?

Thread ID:

Created:

Updated:

Platform:

Replies:

127778 Dec 8,2016 12:40 PM UTC Dec 13,2016 12:14 PM UTC Xamarin.Forms 7
loading
Tags: SfListView
Emil
Asked On December 8, 2016 12:40 PM UTC

Hi,

I am looking for using datasource with listview but documentation example is only with C# behind code. is it possible using mvvm and binding on xaml? can you provide me please some information?

thank you very much.

Emil

Dinesh Babu Yadav [Syncfusion]
Replied On December 9, 2016 11:31 AM UTC

Hi Emil, 
 
Thank you for contacting Syncfusion Support. 
 
You can work with our SfListView using the MVVM pattern and binding on XAML. We have mentioned the code examples like loading, sorting and grouping with DataSource in both XAML  and C# code with Tabs on our SfListView documentation. Please find the UG link for your reference, 
 
 
For your reference, we have attached the sample also. Please find the sample link below, 
 
 
Please let us know if you have any queries. 
  
Regards, 
Dinesh Babu Yadav 


Emil
Replied On December 9, 2016 12:17 PM UTC

Hi Dinesh,

thanks for your suggestion. just a quick question, Is it any different than sfDataGrid? It has also grouping. is there any difference?
on the other hand, I have also wp8.1 app, i think that sfListview doesnt support it, correct?

thanks,

Emil 

Dinesh Babu Yadav [Syncfusion]
Replied On December 9, 2016 02:26 PM UTC

Hi Emil, 
 
·       DataSource is different than SfDataGrid. Please find the differentiation below. 
o   DataSource – It is a non-UI component that consumes raw data and processes data operations such as sorting, filtering and grouping. 
o   SfDataGrid – It is an UI component which display and manipulate the data in a tabular (Multi-column) view.  
o   SfListView – It is a layout control to load the items in a linear manner with some set of features. In future, different layouts (Grid, Wrap, Staggered, etc.) will be added into this. It uses the DataSource internally to processes the data. 
 
·       Yes, SfListView don’t have support for Windows Platform 8.1 application. 
 
Please let us know if you have any queries. 
  
Regards, 
Dinesh Babu Yadav 


Emil
Replied On December 9, 2016 04:22 PM UTC

Hi Dinesh,

One last question please. 
Is it possible have AllowGroupExpandCollapse option like SfListView.AllowGroupExpandCollapse ?
Because datasource exposes already a method called  AutoExpandGroups() method. But I cant find AllowGroupExpandCollapse or after all collapsed, how to expend back. here is my code as below.

It works fine, all will be colapsed if i use dataSource.AutoExpandGroups = false; but how to expland again?

  dataSource.GroupDescriptors.Add(new GroupDescriptor()
            {
                PropertyName = "Title",
                KeySelector = (object obj1) =>
                {
                    var item = (obj1 as Helpers.Models.ExerciseDetailModel);
                    return item.Title.ToString();
                }
            });

          dataSource.AutoExpandGroups = false;

   private  void ViewCell_BindingContextChanged(object sender, EventArgs e)
        {
            try
            {
                ViewCell viewCell = sender as ViewCell;
                var rs= viewCell.BindingContext as GroupResult;
                if (viewCell.BindingContext is GroupResult)
                {
                    var label = new Label()
                    {
                        TextColor = Color.Black,
                        FontSize = 14,
                        HeightRequest = 30,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment = TextAlignment.Center,
                        BackgroundColor = Color.Gray
                    };
                    label.SetBinding(Label.TextProperty, new Binding("Key"));
                    viewCell.View = label;
                }
            }
            catch (Exception)
            {
                 
            }
           
        }


Pannir Selvam S [Syncfusion]
Replied On December 12, 2016 03:36 AM UTC

Hi Emil, 
 
You can achieve your requirement “Expand or Collapse the particular group” by calling the ExpandGroup  or CollapseGroup method. To expand or collapse all the groups at runtime, you can call the ExpandAll or CollapseAll method of SfListView. 
 
Code example [C#]:  
  
// To expand or collapse a group 
var group = listView.DataSource.Groups[0]; 
listView.ExpandGroup(group); 
listView.CollapseGroup(group); 
 
//To expand or collapse all the groups 
listView.ExpandAll(); 
listView.CollapseAll(); 
 
  
If you want to expand or collapse the groups, please refer the below documentation for more details  
 
  
Regards, 
Pannir 


Emil
Replied On December 12, 2016 04:48 PM UTC

Hi Pannir,

thanks for your reply. But what is the event after tapping on the groupitem or KeySelector 

Pannir Selvam S [Syncfusion]
Replied On December 13, 2016 12:14 PM UTC

Hi Emil, 

In SfListView, ItemTapped event is fired when tap on a group header, header and normal item. And you can identify the tap on group header item by checking the ItemType from event arguments like below code example. 

Code Example [C#]: 
ListView.ItemTapped += ListView_ItemTapped; 
 
private void ListView_ItemTapped(object sender, ItemTappedEventArgs e) 
{ 
    if(e.ItemType == Syncfusion.ListView.XForms.ItemType.GroupHeader) 
    { 
        var group = e.ItemData as GroupResult; 
        var key = group.Key; 
    } 
} 

Regards, 
Pannir 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;