Working with SfListView and Prism for Xamarin.Forms.
Xamarin ListView allows the user working it with Prism Tool for MVVM Framework. It can be done by following the below steps
- Replace the Application to PrismApplication in App.xaml file
- Inherited App.xaml.cs from PrismApplication instead of Application.
- Create prism namespace library reference in xaml file of ContentPage.
- Connect view and view model instead of binding context by registering.
Refer the below code snippet which illustrates, how to initialize prism and to register the view with view model.
C#
public partial class App : PrismApplication { public App(IPlatformInitializer initializer = null) : base(initializer) { } protected override void OnInitialized() { InitializeComponent(); } protected override void RegisterTypes() { Container.RegisterTypeForNavigation<MainPage, MainPageViewModel>(); } }
XAML
<?xml version="1.0" encoding="utf-8" ?> <prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:prism="clr-namespace:Prism.Unity;assembly=Prism.Unity.Forms" x:Class="ListViewPrism.App"> </prism:PrismApplication>
Refer the below code snippet which illustrated how to insert the SfListView and to provide prism namespace library reference in ContentPage.
XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" xmlns:local="clr-namespace:ListViewPrism;assembly=ListViewPrism" xmlns:listView="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" x:Class="ListViewPrism.Views.MainPage" Title="MainPage"> <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <listView:SfListView x:Name="listView" ItemSize="70" ItemSpacing="0,0,5,0" AutoFitMode="Height" ItemsSource="{Binding contactsinfo}" IsStickyHeader="True" AllowSwiping="True" IsStickyGroupHeader="True" GroupHeaderSize="50"> </listView:SfListView> </StackLayout> </ContentPage>
Note: https://xamgirl.com/prism-in-xamarin-forms-step-by-step-part-1
Click here to download the sample
Conclusion
I hope you enjoyed learning about working with SfListView and Prism for Xamarin.Forms.
You can refer to our Xamarin.Forms ListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!