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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind OData to Xamarin.Forms ListView (SfListView)

Platform: Xamarin.Forms |
Control: SfListView |
Published Date: March 13, 2020 |
Last Revised Date: March 13, 2020

You can bind the OData as the DataSource to SfListView using the OData Client library in Xamarin.Forms.

 

NuGet to use ODataClient in your application

You need to install the Simple.OData.Client to your application to feed the OData to SfListView.

C#

Fetches the OData using ODataClient using the OData library.

private void SetSource(IEnumerable<Package> packages)
{
    Packages = packages.Select(x => new PackageViewModel(x));
}
 
private async Task<IEnumerable<Package>> GetPackages()
{
    var odataClient = new ODataClient("https://nuget.org/api/v1");
    var command = odataClient
        .For<Package>("Packages")
        .OrderByDescending(x => x.DownloadCount)
        .Top(20);
 
    command.OrderBy(x => x.Id);
    command.Filter(x => x.Title.Contains("Xamarin") && x.IsLatestVersion);
    command.Select(x => new { x.Id, x.Title, x.Version, x.LastUpdated, x.DownloadCount, x.VersionDownloadCount, x.PackageSize, x.Authors, x.Dependencies });
 
    return await command.FindEntriesAsync();
}

C#

Bind the OData to SfListView.

<syncfusion:SfListView ItemsSource="{Binding Packages}"
                        AutoFitMode="DynamicHeight">
    <syncfusion:SfListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <StackLayout Padding="5,5"
                                    Orientation="Vertical"
                                    VerticalOptions="FillAndExpand">
                        <Label Text="{Binding ShortSummary}"/>
                    </StackLayout>
                </ViewCell.View>
            </ViewCell>
        </DataTemplate>
    </syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>

 

Output

OData

View sample in GitHub

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile