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. Regarding treeview using MVVM pattern

Regarding treeview using MVVM pattern

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfdata-structuresregex
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.
  • R Offline
    R Offline
    Ravi Mori
    wrote on last edited by
    #1

    Hi.. I am using hierarchical data template in tree view in my wpf application using mvvm pattern. Binding of data using observable collection done successfully through viewmodel.. But my problem is in getting selected item.. Can anybody tell me how to get selected item in treeview in mvvm pattern.....?

    P M 2 Replies Last reply
    0
    • R Ravi Mori

      Hi.. I am using hierarchical data template in tree view in my wpf application using mvvm pattern. Binding of data using observable collection done successfully through viewmodel.. But my problem is in getting selected item.. Can anybody tell me how to get selected item in treeview in mvvm pattern.....?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Try reading Josh's article on MVVM with the Treeview[^]. Download the code and see how Josh does it.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • R Ravi Mori

        Hi.. I am using hierarchical data template in tree view in my wpf application using mvvm pattern. Binding of data using observable collection done successfully through viewmodel.. But my problem is in getting selected item.. Can anybody tell me how to get selected item in treeview in mvvm pattern.....?

        M Offline
        M Offline
        Mike Fuchs
        wrote on last edited by
        #3

        I only tested this in Silverlight, should be the same in WPF though. You can in fact bind to SelectedItem on the TreeView <controls:TreeView ItemsSource="{Binding KeywordSource}" SelectedItem="{Binding SelectedKeyword, Mode=TwoWay}"> Blend throws an error, noting (correctly) that SelectedItem has not have an accessible setter, which is also the reason you will not get the SelectedItem in Intellisense. If I understand correctly however, you just need the getter, which is working for me.

        R 1 Reply Last reply
        0
        • M Mike Fuchs

          I only tested this in Silverlight, should be the same in WPF though. You can in fact bind to SelectedItem on the TreeView <controls:TreeView ItemsSource="{Binding KeywordSource}" SelectedItem="{Binding SelectedKeyword, Mode=TwoWay}"> Blend throws an error, noting (correctly) that SelectedItem has not have an accessible setter, which is also the reason you will not get the SelectedItem in Intellisense. If I understand correctly however, you just need the getter, which is working for me.

          R Offline
          R Offline
          Robert Graves
          wrote on last edited by
          #4

          Setting the Mode on the Binding of the SelectedItem to OneWayToSourceeliminates the error message

          <controls:TreeView ItemsSource="{Binding KeywordSource}" SelectedItem="{Binding SelectedKeyword, Mode=OneWayToSource}">

          I lied, throws a compile time error...

          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