List<T> to ObservableCollection<T> RRS feed

  • Question

  • 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>?



    Tuesday, November 24, 2020 11:30 PM

All replies

  • Hello,

    Best to post your question in this forum and use a tag of wpf.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    My GitHub code samples
    GitHub page

    Check out:  the new Microsoft Q&A forums

    Tuesday, November 24, 2020 11:38 PM
  • Well, these 2 classes are not WPF specific, so I think I'll answer it directly:

    ObservableCollection<T> variableToBind = new ObservableCollection<T>(yourList);

    Just passing it to constructor will work. It's totally okay not to modify the backend because this class belongs to System.Collections.ObjectModel namespace, where we usually don't use any of the types there across process boundary.

    Wednesday, November 25, 2020 2:01 AM