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. Get Data from ViewModel in Code behind using MVVM

Get Data from ViewModel in Code behind using MVVM

Scheduled Pinned Locked Moved WPF
architecturewpfhelp
4 Posts 4 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.
  • N Offline
    N Offline
    NTheOne
    wrote on last edited by
    #1

    Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..

    M A S 3 Replies Last reply
    0
    • N NTheOne

      Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      this.LayoutRoot.DataContext

      This assumes the layoutroot has the data context assigned (otherwise just this.datacontext). You will also need to cast the datacontext back to your viewmodel

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N NTheOne

        Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        You should be setting the Datacontext of the page to the viewmodel somewhere if you are implementing MVVM correctly.

        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

        1 Reply Last reply
        0
        • N NTheOne

          Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..

          S Offline
          S Offline
          SledgeHammer01
          wrote on last edited by
          #4

          One of the aspects of MVVM is that you don't have any code behind. The only thing thats "allowed" in the code behind is manipulating visuals. The fact that you want to interact with the ViewModel from the code behind is definitely wrong.

          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