In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how WPF binds hierarchical data. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
There are many types of hierarchical data in practical project applications, and WPF provides a good data binding mechanism. Among them, ListBox and TreeView controls are used most frequently.
I. the difference between ListBox and TreeView controls
1.ListBox displays single-level data sets, while TreeView can display single-level and multi-level data sets.
two。 The good data display effect can be displayed at the UI level through ListBox, and the data sets can be sorted, grouped and filtered.
3.TreeView is displayed as a multi-level data set with a tree structure, and its well-defined data display effect can also be defined through Templete and Style properties.
2. ListBox control example
1.ListBox binding data is grouped:
Using the ListBox.GridStyle tag, define the HeaderTemplate attribute that defines the appearance of the group header:
The code is as follows:
Code
.
This creates an effect similar to that of the WINDOWS file manager:
Some experience with 2.Listbox:
/ 1 if you want to achieve a beautiful interface similar to WINDOWS and group it, you need to customize the style of GroupStyle, otherwise WPF will use the built-in GroupStyle, or you can reference the static property of GroupStyle.Default.
/ 2 ListBox can only define one layer of data structure. If ListBox is used again in Item in ListBox, the ItemSource in ListBox will not inherit the data set from the Item source of the upper layer ListBox, such as the following data set:
The copy code is as follows:
Public List groups = new List (); groups.Add (new Group);.
The copy code is as follows:
Public class Group {
Public int Id {get; set;}
Public string Name {get; set;}
Private List boxes = new List ()
Public List Boxes {
Get {return boxes;}
}
}
The data set of Listbox's ItemSource Binding List, and the ListBox Binding List in its Item, then the ListBox in Item cannot obtain the data set of List.
Third, TreeView control example
1. As with the data set above, use TreeView to bind multi-tier data sets:
The copy code is as follows:
Code
The HierarchicalDataTemplate attribute is a hierarchical data template, which inherits the hierarchical structure of the data collection, and HierarchicalDataTemplate must be used to represent the hierarchical dependencies of the tree.
Attribute binding data using TwoWay is a bi-directional property, when the source data or target is changed to update the other party's data. The typical application in hierarchical tree representation is to use CheckBox to select child nodes and transfer unselected states.
Thank you for reading! This is the end of the article on "how to bind hierarchical data in WPF". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.