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. C#
  4. Problems with treeview in WPF

Problems with treeview in WPF

Scheduled Pinned Locked Moved C#
wpfhelpquestioncsharpdata-structures
2 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.
  • S Offline
    S Offline
    sinosoidal
    wrote on last edited by
    #1

    Hi, I have made a custom class to populate a TreeView thru its ItemsSource. That class heritates ObservableCollection. The thing is that its nodes doesnt seem to be TreeViewItems because i cant apply code that works for normal treeviewitems. I'm talking about code to do right click select, etc. What i really want is to be able to automaticly select a node when i right click it, and then open the context menu. I can do this perfectly using the left button to select the node and then using the right click to access the context menu. The problem is that i cant use directly the right button which is something typical in windows enviorment. The code i'm using to achieve that is the following: Code Snippet tvNetworkExplorer.AddHandler(TreeViewItem.MouseDownEvent, new MouseButtonEventHandler(TvNetworkExplorer_MouseDown)); private void TvNetworkExplorer_MouseDown(object sender, MouseButtonEventArgs e) { TreeViewItem item = e.Source as TreeViewItem; if (e.RightButton == MouseButtonState.Pressed) { item.IsSelected = true; } } I think this happens because the items are not tree view items, as stated before, they are items from an observable collection of a custom type. How can i make such behaviour to happen? The problem is that even using the visual tree help i always get the first node. I need to show you the big picture. Maybe i have something really small failing: XAML:

    A 1 Reply Last reply
    0
    • S sinosoidal

      Hi, I have made a custom class to populate a TreeView thru its ItemsSource. That class heritates ObservableCollection. The thing is that its nodes doesnt seem to be TreeViewItems because i cant apply code that works for normal treeviewitems. I'm talking about code to do right click select, etc. What i really want is to be able to automaticly select a node when i right click it, and then open the context menu. I can do this perfectly using the left button to select the node and then using the right click to access the context menu. The problem is that i cant use directly the right button which is something typical in windows enviorment. The code i'm using to achieve that is the following: Code Snippet tvNetworkExplorer.AddHandler(TreeViewItem.MouseDownEvent, new MouseButtonEventHandler(TvNetworkExplorer_MouseDown)); private void TvNetworkExplorer_MouseDown(object sender, MouseButtonEventArgs e) { TreeViewItem item = e.Source as TreeViewItem; if (e.RightButton == MouseButtonState.Pressed) { item.IsSelected = true; } } I think this happens because the items are not tree view items, as stated before, they are items from an observable collection of a custom type. How can i make such behaviour to happen? The problem is that even using the visual tree help i always get the first node. I need to show you the big picture. Maybe i have something really small failing: XAML:

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

      I'm facing the same problem. I somehow managed to get it selected in the similar way and opened the contextmenu like TreeViewItem.ContextMenu.IsOpen=true; but the problem that occurred was, the commands bindings to the menu items(in xaml) don't work. :confused:

      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