List<T> to ObservableCollection<T>

Y a h y a 416 Reputation points
2020-11-25T01:50:44.91+00:00

Hi

In my Xamarin app the page is bound to an ObservableCollection<T> but the remote Api is currently returning List<T>. What is the best way to handle this discrepancy? Should I change the backend Api to return ObservableCollection<T>?

Thanks

Regards

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LandLu-MSFT 21 Reputation points
    2020-11-25T02:21:56.333+00:00

    Hello,

    Welcome to Microsoft Q&A!

    We could easily convert list to observable through:

    ObservableCollection<int> myCollection = new ObservableCollection<int>(myList);  
    

    Change the int to your object in your case.

    Thank you.


    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.