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. How do I hook PropertyChanged in an ObservableCollection<EF objects>

How do I hook PropertyChanged in an ObservableCollection<EF objects>

Scheduled Pinned Locked Moved WPF
questiontutorialdatabaselearning
1 Posts 1 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.
  • D Offline
    D Offline
    Duke Carey
    wrote on last edited by
    #1

    Pardon the lengthy preamble here, but I'm pretty sure I've wandered a ways down the wrong path and need a bit of conceptual guidance. I'm a hobby programmer (with big gaps in knowledge) and I'm trying to learn how to handle editing a many-to-many relationship and attempting to do so with a listbox containing checkboxes. I'm using a simplistic example of Movie entities and Genre entities - each in their own 2 column SQL table of ID and Title or GenreName. A pure mapping table (MovieGenre) represents the M-t-M relationship. I'm using Entity Framework and, of course, EF hides that mapping table. I want to present all the possible Genres in a listbox with checkboxes and let the user check which ones to assign. To have something to bind the check portion to I created a partial class for Genre and added a bool IsSelected property. When the user selects a movie, the ViewModel loads up an ObservableCollection of the Genres and sets the IsSelected property to true for each Genre already assigned to that movie, false for all the others. So far so good. The screen works as desired. But editing does not. When a checkbox is checked I want to add that Genre to the movie's Genre collection, but can't seem to capture the PropertyChanged notification within the ViewModel. I can do it in the Genre's partial class, but there I don't know anything about the selected movie and cannot modify the movie's Genre collection. So, conceptually, how can I structure this so that the ViewModel knows that the IsSelected property on a specific Genre within the ObservableCollection has changed?

    I'm in the Witless Protection Program

    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