TLDR
TLDR

Reputation: 1278

What pattern is appropriate for combining a DataSource, Prism 6, and a Xamarin.Forms.Behavior?

In v1 of my application, I am using an asynchronous REST service to load the contents of a ListView in Xamarin forms, with Prism binding the View and the ViewModel.

I want to enhance the GUI with some features that are implemented in a Xamarin.Forms Behavior, and this is my first attempt at merging this Syncfusion demo into my Prism Application.

My current code (v1) looks like this: (note the REST call

    public MyPeopleListViewModel(INavigationService navigationService, IEventAggregator ea) : base(navigationService, ea)
    {
        Title = "Contacts";

        tapCommand = new Command<Syncfusion.ListView.XForms.ItemTappedEventArgs>(OnTapped);
        loadedCommand = new Command<SfListView>(OnListViewLoaded);
        swipeImageCommand = new Command<Models.TrustedContactItem>(OnSwipeImageTapped);
        swipeCommand = new Command<SwipingEventArgs>(OnSwipeCommand);

        MyContactsList = new ObservableCollection<Models.TrustedContactItem>();

        // THIS PART IS RELEVANT TO THE STACKOVERFLOW QUESTION
        LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync());

        _navigationService = navigationService;
    }

... where the most important section is annotated above

My question is how do I correctly reference a Behavior from within a behavior?

Does the Behavior automatically make the Prism AutoBinding features of connecting the View and ViewModels together irrelevant?

enter image description here ... larger image here

How do I implement a behavior that loads this view, while using Prism?

Upvotes: 0

Views: 157

Answers (1)

kyuubi
kyuubi

Reputation: 71

We would like to let you know that while using prism, it is not neccessary to create new instance for ViewModel class as it will be already registered along with the MainPage in App.Xaml.cs. So in the Behavior class you can get the ViewModel instance from the SfListView’s BindingContext while expanding or collapsing the items[Accordion like view] in the ItemTapped event.

For more details, you can refer the below UG documentation.

https://help.syncfusion.com/xamarin/sflistview/mvvm#listview-with-prism-framework

For your assistance, we have attached the modified sample and you can download it from the below link.

Sample link: http://www.syncfusion.com/downloads/support/directtrac/216438/ze/SfListViewSample-1851048626

You can fetch and load items inside SFListView from the specified URL. As we haven’t got any specific REST services available at our end, we suggest you to follow the procedures given the below link to achieve your requirement.

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/consuming/rest

You can load more items into the collection by fetching data from the online server. You can refer the below documentation link to know about the procedure to load more items on demand in SfListView.

https://help.syncfusion.com/xamarin/sflistview/loadmore

Please let us know if you require further details.

Regards,
G.Muthu kumaran.

Upvotes: 1

Related Questions