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. One data context for multiple Controls

One data context for multiple Controls

Scheduled Pinned Locked Moved WPF
question
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.
  • C Offline
    C Offline
    columbos14927
    wrote on last edited by
    #1

    Hello, I have a window and a user control in side of the window. I want to set the same ViewModel class as a data context for both,the window and the user control. how can i do it? Thanks

    A 1 Reply Last reply
    0
    • C columbos14927

      Hello, I have a window and a user control in side of the window. I want to set the same ViewModel class as a data context for both,the window and the user control. how can i do it? Thanks

      A Offline
      A Offline
      AlphaDeltaTheta
      wrote on last edited by
      #2

      Data contexts are inherited. the data context for a control is automatically passed into all it's children unless it declares a different one for it's own. So the data context for the window is automatically inherited by your UserControl. PS: I assume your UserControl is a child of the window

      C 1 Reply Last reply
      0
      • A AlphaDeltaTheta

        Data contexts are inherited. the data context for a control is automatically passed into all it's children unless it declares a different one for it's own. So the data context for the window is automatically inherited by your UserControl. PS: I assume your UserControl is a child of the window

        C Offline
        C Offline
        columbos14927
        wrote on last edited by
        #3

        Thanks!!!

        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