In this blog post, you will learn how to use Bindable Layout in Xamarin.Forms.
IntroductionXamarin.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.
- ItemsSource – Gets sets the collection of IEnumerable items to template and display.
- ItemDataTemplate – Gets sets DataTemplate to apply to each item in the collection of items displayed layout.
- ItemTemplateSelector – DataTemplateSelector that will be used to choose a DataTemplate for an item at runtime.
- Visual Studio 2017 or later (Windows or Mac)
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 :)
Thank you so much for sharing this excellent information. Your article is amazing. Good to discover your post
ReplyDeleteHire Xamarin Developer Texas, USA
Thanks for sharing this informative content , Great work
ReplyDeleteLeanpitch provides online training in Product prototyping during this lockdown period everyone can use it wisely.
icp-cat training
Thanks for sharing this informative content , Great work
ReplyDeleteRead this Blog to become a perfect Product Manager : Best Books for Product managers
Thanks for sharing this informative content , Great work
ReplyDeleteRead this Blog to know about Scrum artifacts : Scrum Artifacts
Thanks for sharing this informative content , Great work
ReplyDeleteRead this blog to know about : Definition of done
What is the source code for BaseViewModel you're inheriting from?
ReplyDelete