Analysis of the structure of the tree of WPF

Evolved into routed events (Routed event), and the derived command transfer mechanism on its basis. These mechanisms largely reduce the shackles of programmers, so that the design and implementation procedures more flexible coupling between modules to further reduce

The effect routing (Route) word is this: there are several transit point between the beginning and the end, after starting from the starting point after each

Path select transfer station to make the final correct (such as the shortest or fastest) reach the end. The nature of programming is to use the compiler (and sometimes must rely on libraries) to extend the functionality of the operating system, so the base can not run the program from the operating system - Windows itself is a message-driven operating system, so our programs are doomed is a message-driven, when the program runs also make their message system and the entire operating system message system "communication" and it can be performed in response. Throughout several generations of Windows application development platform, the earliest Windows apl development (C language) and MC development we can directly see the various messages and you can define your own messages; to the COM and ⅤB era, the message is packaged as an event (Event) and has been used to NET platform development - no matter how that essence between program modules communicate with each other using the message is not changed. Develop a direct message from Windows api to upgrade the model for the message passing model - we already know that WPF front of U is a tree structure consisting of the layout of components and controls, when a node of this tree inspire a event, the programmer can choose to direct the traditional event model

Let's responder responds, so that the event may be transmitted in the UI component tree along a certain direction and passing through a plurality of transit nodes, and is appropriately processed in the routing process. You can put WPF routed events seen as a small ant, it can crawl from the base to the top of the tree (or reverse) target, every passing a bifurcation branch will bring this message to the bifurcation point person to the recipient (host or event occurred directly handled by the event handler event responders). WPF to this most cases we are dealing with Logical Tree, and sometimes in order to achieve some tricky feature to Visual tree for help,

According to personal opinion, if your application needs the
Visual tree to accomplish some business logic (rather than pure performance logic) related functions, mostly by the program poorly designed and caused, please reconsider the logic, functions and data types of design

If you want to find the Logical Tree or navigation elements may be implemented by means of a static method LogicalTreeHelper class: BringInto View: The user selected elements into the viewable area, often used in view of the scrollable

FindLogicalNode: the given name (Name property value) to find the element, including child elements tree.

Getchildren: Get all direct child elements.

GetParent: Gets the immediate parent element.

If you want to Visual tree navigation or find an element, you can help Ⅴ static method / isualTreeHelper class to achieve.

Now we already know, WPF's U can be expressed as Logical Tree and Visual Tree, then when a routing event

After being excited is passed along the Logical Tree or pass along the Visual tree? The answer is vi
isual tree- Only in this way, "hidden" in the Template control in order to send a message out.

example:

var rootItem = new
OutlineTreeData

{

outlineTypeName = “David
Weatherbeam”,

Children=

{

new OutlineTreeData

{

outlineTypeName=“Alberto Weatherbeam”,

Children=

{

new OutlineTreeData

{

outlineTypeName=“Zena Hairmonger”,

Children=

{

new
OutlineTreeData

{

outlineTypeName=“Sarah Applifunk”,

}

}

},new
OutlineTreeData

{

outlineTypeName = "Jenny of Macho Queen",

Children=

{

new
OutlineTreeData

{

outlineTypeName = "Nick Macho Queen"

},

new
OutlineTreeData

{

outlineTypeName=“Matilda Porcupinicus”,

},

new
OutlineTreeData

{

outlineTypeName=“Bronco van Machoqueen”,

}

}

}

}

},

new OutlineTreeData

{

outlineTypeName=“Komrade Winkleford”,

Children=

{

new OutlineTreeData

{

outlineTypeName=“Maurice Winkleford”,

Children=

{

new OutlineTreeData

{

outlineTypeName=“Divinity W. Llamafoot”,

}

}

},

new OutlineTreeData

{

outlineTypeName=“Komrade Winkleford, Jr.”,

Children=

{

new
OutlineTreeData

{

outlineTypeName=“Saratoga Z. Crankentoe”,

},

new OutlineTreeData

{

outlineTypeName=“Excaliber Winkleford”,

}

}

}

}

}

}

};

Guess you like

Origin blog.csdn.net/weixin_44589117/article/details/90580267