WPF: TreeViewItem bound to an ICommand

后端 未结 6 624
离开以前
离开以前 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:51

    I know this was "answered" a while ago, but since the answers weren't ideal, I figured I'd put in my two cents. I use a method that allows me to not have to resort to any "styled button trickery" or even using code-behind and instead keeps all my separation in MVVM. In your TreeView add the following xaml:

    
        
            
        
    
    

    In your xaml header add:

    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    

    and then you'll have to add a reference to the above assembly in your project.

    After that, everything acts just the same as any other command would on say a button or something.

提交回复
热议问题