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,

CodePudding user response:

reference 4 floor exception92 response:
selected tree node's parent
-> Operating data source is more convenient, want to get discouraged by operating the UI,

How to operate the data source Node, please?

CodePudding user response:

Forget to add a of this
Public Node ()
{
The Children=new ObservableCollection (a);
}

CodePudding user response:

refer to 6th floor hez2010 response:
VisualizationTree can search to the parent node

Because of my tree is the bound data source, what I want is control binding object,

CodePudding user response:

refer to the eighth floor opencv_newers response:
Quote: refer to 4th floor exception92 response:

The selected tree node's parent
-> Operating data source is more convenient, want to get discouraged by operating the UI,

How to operate the data source Node, please?

You need when binding data to determine the relationship between the node, which is the node class must contain a node in the superclass object, said the node to the parent node,

CodePudding user response:

11 references exception92 response:
Quote: refer to the eighth floor opencv_newers response:

Quote: refer to 4th floor exception92 response:

The selected tree node's parent
-> Operating data source is more convenient, want to get discouraged by operating the UI,

How to operate the data source Node, please?

You need when binding data to determine the relationship between the node, the node is in the class must contain a node superclass object, said the parent node of the node,

This is I write node constructors, I don't know what I said in the constructor of the node parent node
Private ObservableCollection children;
Public ObservableCollection The Children
{
The get
{
Return the children;
}
Set
{
The children=value;
OnPropertyChanged (" Children ");
}
}

Private Node parent;
Public Node Parent
{
The get
{
Return the parent;
}
Set
{
The parent=value;
OnPropertyChanged (" Parent ");
}
}
Public Node ()
{
The Children=new ObservableCollection (a);

}

CodePudding user response:

refer to 12 floor opencv_newers reply:
Quote: reference 11 floor exception92 response:

Quote: refer to the eighth floor opencv_newers response:

Quote: refer to 4th floor exception92 response:

The selected tree node's parent
-> Operating data source is more convenient, want to get discouraged by operating the UI,

How to operate the data source Node, please?

You need when binding data to determine the relationship between the node, the node is in the class must contain a node superclass object, said the parent node of the node,

This is I write node constructors, I don't know what I said in the constructor of the node parent node
Private ObservableCollection children;
Public ObservableCollection The Children
{
The get
{
Return the children;
}
Set
{
The children=value;
OnPropertyChanged (" Children ");
}
}

Private Node parent;
Public Node Parent
{
The get
{
Return the parent;
}
Set
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related