<controls:TreeView Height="133" HorizontalAlignment="Left" Margin="29,23,0,0" Name="treeView1" VerticalAlignment="Top" Width="200"> <controls:TreeViewItem Header="中国" IsExpanded="True"> <controls:TreeViewItem Header="北京" /> <controls:TreeViewItem Header="上海" IsSelected="True" /> <controls:TreeViewItem Header="济南" /> </controls:TreeViewItem> <controls:TreeViewItem Header="美国" /> <controls:TreeViewItem Header="日本"> <controls:TreeViewItem Header="大阪" /> <controls:TreeViewItem Header="神户" /> </controls:TreeViewItem> </controls:TreeView>
2,Name, Height, Width,
Header, IsExpanded[是否展开], IsSelected[是否选中状态]
3,
//取值 string str1aHeader = ((TreeViewItem)treeView1.SelectedItem).Header.ToString();
4,
1.B,返回顶部 TreeView控件(树形视图控件)-逐个添加项 1,<controls:TreeView Height="100" HorizontalAlignment="Left" Margin="34,152,0,0" Name="treeView2" VerticalAlignment="Top" Width="200" />
2,文字同上 1.A.2
3,//A:TreeView2 逐个添加项 //第一层 TreeViewItem item1b = new TreeViewItem(); item1b.Header = "China"; item1b.IsExpanded = true; //展开节点 #region 第二层,增加子节点 item1b.Items.Add("Beijing"); item1b.Items.Add(new TreeViewItem() { Header="Shanghei",IsSelected=true }); item1b.Items.Add("Ji'nan"); #endregion TreeViewItem item3b = new TreeViewItem(); item3b.Header = "Japan"; #region 第二层,增加子节点 item3b.Items.Add("Daban"); item3b.Items.Add("Shenhu"); #endregion treeView2.Items.Add(item1b); //添加项 treeView2.Items.Add("American"); treeView2.Items.Add(item3b);
4,
1.C,返回顶部TreeView控件(树形视图控件)-绑定合集 1,<controls:TreeView Height="100" HorizontalAlignment="Left" Margin="252,23,0,0" Name="treeView3" VerticalAlignment="Top" Width="200" />
2,文字同上 1.A.2
3,//B:TreeView3 绑定合集 IList<TreeViewItem> roots = new List<TreeViewItem>(); TreeViewItem item1c = new TreeViewItem(); item1c.Header = "China"; item1c.IsSelected = true; #region 第二层,增加子节点 item1c.Items.Add("Beijing"); item1c.Items.Add(new TreeViewItem() { Header = "Shanghei", IsSelected = true }); item1c.Items.Add("Ji'nan"); #endregion roots.Add(item1c); TreeViewItem item3 = new TreeViewItem(); item3.Header = "American"; roots.Add(item3); TreeViewItem item3c = new TreeViewItem(); item3c.Header = "Japan"; #region 第二层,增加子节点 item3c.Items.Add("Daban"); item3c.Items.Add("Shenhu"); #endregion roots.Add(item3c); treeView3.ItemsSource = roots; //绑定集合
4,
作者:ylbtech