Msdn tutorial short film WPF 21 (binding 4-treeview, menu)

Source: Internet
Author: User

We introduced how to bind data to ListBox last time. Today we bind data to Treeview and menu. The difference is that datatemplate. Instead of datatemplate, hierarchicaldatatemplate is used.

This is a layered data template, and hierarchical is a layered data template. Datatemplate is a data template. This is easy to remember.

We still use the last data.

Let's look at. XAML.

 Code <Window. Resources> <objectdataprovider X: Key =" ODP "Objecttype =" {X: Type SRC: leaguelist} "/> <Hierarchicaldatatemplate datatype =" {X: Type SRC: League} "Itemssource =" {Binding Path = divisions} "> <Textblock text =" {Binding Path = Name} "/> </Hierarchicaldatatemplate>  {X: Type SRC: Division} "Itemssource =" {Binding Path = teams} "> <Textblock text =" {Binding Path = Name} "/> </Hierarchicaldatatemplate> <datatemplate datatype =" {X: Type SRC: Team} "> <Textblock text =" {Binding Path = Name} "/> </Datatemplate> </window. Resources>

Do not forget to add your own namespace SRC.

Datatype in hierarchicaldatatemplate is: gets or sets the type for this datatemplate.

Itemssource is a data class bound to the next layer.

Treeview binding

Next, let's look at the Treeview:

 
Code<Treeview Height ="200"Horizontalalignment ="Left"Margin =", 0"Name ="Treeview1"Verticalalignment ="Top"Width ="167"> <Treeviewitem header =" competition team "itemssource ="{Binding source = {staticresource ODP }}"> </Treeviewitem> </Treeview>

You can press f5.

Menu binding
Code<Menu Height ="23"Horizontalalignment ="Left"Margin =", 0"Name ="Menu1"Verticalalignment ="Top"Width ="167"> <Menuitem header =" competition team "itemssource ="{Binding source = {staticresource ODP }}"> </Menuitem> </menu>

Menu binding is much easier.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.