WPF: TreeViewItem bound to an ICommand

后端 未结 6 795
离开以前
离开以前 2021-02-08 19:24

I am busy creating my first MVVM application in WPF.

Basically the problem I am having is that I have a TreeView (System.Windows.Controls.TreeView) which I have placed

6条回答
  •  梦谈多话
    2021-02-08 19:49

    What I'd do is set the Header of the TreeViewItem to be a button, then skin the button so that it doesn't look or act like one, then perform my command binding against the button.

    You might need to do this via a DataTemplate, or you might need to change the template of the TreeViewItem itself. Never done it, but this is how I've done similar things (such as tab page headers).


    Here's an example of what I'm talking about (you can drop this in Kaxaml and play around with it):

    
       
          
       
       
          
             
                
             
          
       
    
    

    I've created a new clear style for a button. I then just drop a button in the TVI and set its style. You can do the same thing using data templates, of course.

提交回复
热议问题