Home > Net > Inquire of the WPF MVVM mode how to get the selected tree node's parent
Inquire of the WPF MVVM mode how to get the selected tree node's parent
Time:10-19
Inquire of the WPF MVVM mode how to get the selected tree node's parent Var node=this. Tree. SelectedItem as node; ,,, .
CodePudding user response:
CodePudding user response:
Want is the parent node object after binding
CodePudding user response:
Attach the code, this is the Node class Public class Node: INotifyPropertyChanged {
Private string nodeName. Public string NodeName { The get { Return the nodeName. } Set { NodeName=value; OnPropertyChanged (" NodeName "); } }
Private bool isExpanded; Public bool IsExpanded { The get { Return isExpanded; } Set { IsExpanded=value; OnPropertyChanged (" IsExpanded "); } }
Private bool an isSelected;
Public bool an IsSelected { The get { Return an isSelected; } Set { An isSelected=value; OnPropertyChanged (" an IsSelected "); } }
Private ObservableCollection children; Public ObservableCollection The Children { The get { Return the children; } Set { The children=value; OnPropertyChanged (" Children "); } }
The public event PropertyChangedEventHandler PropertyChanged; Public void OnPropertyChanged (string propertyName) { If (PropertyChanged!=null) { PropertyChanged (this, new PropertyChangedEventArgs (propertyName)); } } }
CodePudding user response:
The selected tree node's parent -> Operating data source is more convenient, want to get discouraged by operating the UI,
CodePudding user response:
Since you can take to the current node with the entire tree data check to see which the child nodes of the node is the node don't you can take to the parent node
CodePudding user response:
Through VisualizationTree can search to the parent node
CodePudding user response:
Since is MVVM, you do not have direct access to the tree, can use the binding with binding as far as possible,