Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF ObservableCollection vs List Problem

WPF ObservableCollection vs List Problem

Scheduled Pinned Locked Moved WPF
helpcsharpasp-netdatabasevisual-studio
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I'm working on a WPF app. The DAL is behind an MVC 4 WebAPI hitting SQL. I have a one-to-many collection of Addresses & phones. The Address object contains a list of Phone objects. Each address can contain one or many phones. If I create the phone list using List then the UI doesn't see new phones when added. If I create the list using ObservableCollection then when I return the collection from the DAL the phones list is null. The list of phones doesn't serialize coming back from through the API. What's wrong here? What's the right way to do this?

    If it's not broken, fix it until it is

    B 1 Reply Last reply
    0
    • K Kevin Marois

      I'm working on a WPF app. The DAL is behind an MVC 4 WebAPI hitting SQL. I have a one-to-many collection of Addresses & phones. The Address object contains a list of Phone objects. Each address can contain one or many phones. If I create the phone list using List then the UI doesn't see new phones when added. If I create the list using ObservableCollection then when I return the collection from the DAL the phones list is null. The list of phones doesn't serialize coming back from through the API. What's wrong here? What's the right way to do this?

      If it's not broken, fix it until it is

      B Offline
      B Offline
      BenScharbach
      wrote on last edited by
      #2

      I would try to add the serialize attribute to the data-model you mentioned. No sense trying to resolve the WPF part until the data-model part is working from your API. Then I would create a view-model class to separate the data-model class from the WPF window. Add the INotifyProperty pattern to the view-model. And then in xaml, make sure to reference the name of the public properties in your view-model for the collections; like your OC.

      Ben Scharbach Temporalwars.Com YouTube:Ben Scharbach

      K 1 Reply Last reply
      0
      • B BenScharbach

        I would try to add the serialize attribute to the data-model you mentioned. No sense trying to resolve the WPF part until the data-model part is working from your API. Then I would create a view-model class to separate the data-model class from the WPF window. Add the INotifyProperty pattern to the view-model. And then in xaml, make sure to reference the name of the public properties in your view-model for the collections; like your OC.

        Ben Scharbach Temporalwars.Com YouTube:Ben Scharbach

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        You replied to a message from 3 years ago???

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups