question

VuyiswaMaseko-8882 avatar image
0 Votes"
VuyiswaMaseko-8882 asked JessieZhang-2116 answered

How to Refresh CollectionView from another Content View (Template) Xamarin Forms

Good Day All

I have CollectionView view defined like this

<CollectionView x:Name="LstShares" >
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<template:SharesViewTemplate />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

In the Template "template:SharesViewTemplate" i want to refresh the LstShares , by calling the same function that binded it .

Thanks


dotnet-xamarinforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered

Hello,


Welcome to our Microsoft Q&A platform!

A simple method is to use Xamarin.Forms MessagingCenter to achieve this.

In your page, Subscribe message as follows(`PersonCell` is my ViewCell):

     public HomePage ()
     {
         InitializeComponent ();

         MessagingCenter.Subscribe<PersonCell,object>(this, "AddItem", (obj, item) =>
         {
             //var newItem = item as VeggieViewModel;


         });
     }

In ViewCell, send message:

   public partial class PersonCell : ViewCell
 {
     public PersonCell()
     {
         InitializeComponent();

         object obj = new object();

         MessagingCenter.Send(this, "AddItem", obj);
     }
 }

For more details, check: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center


Best Regards,

Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.