Delpin Susai Raj Sunday 24 November 2019

Xamarin.Forms - Bindable Layout

In this blog post, you will learn how to use Bindable Layout in Xamarin.Forms.

Introduction
Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Bindable Layout

Bindable layouts enable any layout class that derives from the Layout<T> class to generate its content by binding to a collection of items, with the option to set the appearance of each item with a DataTemplate. Bindable Layout it's like a ListView.

Bindable Layout Attached properties.
  1. ItemsSource – Gets sets the collection of IEnumerable items to template and display.
  2. ItemDataTemplate – Gets sets DataTemplate to apply to each item in the collection of items displayed layout.
  3. ItemTemplateSelector – DataTemplateSelector that will be used to choose a DataTemplate for an item at runtime.
Prerequisites
  • Visual Studio 2017 or later (Windows or Mac)
Setting up a Xamarin.Forms Project

Start by creating a new Xamarin.Forms project. You wíll learn more by going through the steps yourself.

Create a new or existing Xamarin forms(.Net standard) Project. With Android and iOS Platform.
Bindable Layout

Lets start with how to use Bindable layout in your app instead of listview.

Use Bindable Layout

In this step, use bindable layout in Stacklayout.

MainPage.XAML

Create a Model

Now, Create a simple model to create a collection.

Person.cs

Create a ViewModel

In this step, create a viewmodel to bind the collection to bindable layout.

MainPageViewModel.cs

Selected Item

Use GestureRecognizers for select item from collection, because bindable layout have no ItemSelected event.

MainPage.Xaml


MainPageViewModel.cs


Try it out.
I hope you have understood how to use Bindable Layout in Xamarin.Forms..

Thanks for reading. Please share your comments and feedback. Happy Coding :)

6 comments:

  1. Thank you so much for sharing this excellent information. Your article is amazing. Good to discover your post

    Hire Xamarin Developer Texas, USA

    ReplyDelete
  2. Thanks for sharing this informative content , Great work
    Leanpitch provides online training in Product prototyping during this lockdown period everyone can use it wisely.
    icp-cat training

    ReplyDelete
  3. Thanks for sharing this informative content , Great work
    Read this Blog to become a perfect Product Manager : Best Books for Product managers

    ReplyDelete
  4. Thanks for sharing this informative content , Great work
    Read this Blog to know about Scrum artifacts : Scrum Artifacts

    ReplyDelete
  5. Thanks for sharing this informative content , Great work
    Read this blog to know about : Definition of done

    ReplyDelete
  6. What is the source code for BaseViewModel you're inheriting from?

    ReplyDelete