WPF自定义treeview绑定事件SelectedItemChanged

1、设置事件绑定到函数TreeUAAddressSpace_SelectedItemChanged

 this.treeBrowseUASpace.SelectedItemChanged += new System.Windows.RoutedPropertyChangedEventHandler(this.TreeUAAddressSpace_SelectedItemChanged);


2、绑定的响应函数如下:

 private void TreeUAAddressSpace_SelectedItemChanged(object sender, EventArgs e)
        {
            TreeViewItem treeValue = (TreeViewItem)treeBrowseUASpace.SelectedItem;

}


3、注:这里的树为TreeView treeBrowseUASpace;

      TreeViewItem treeValue即为当前选中的节点的值


4、显示到界面上

       首先设置一个stackpanel控件(拖到界面上就行),classInstance为树所在的类的对象

 PanelUAAddressSpace.Children.Add(classInstance.treeBrowseUASpace);   


你可能感兴趣的:(WPF自定义treeview绑定事件SelectedItemChanged)