码迷,mamicode.com
首页 > 其他好文 > 详细

wpf treeview

时间:2014-06-10 00:43:33      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

首先是xaml代码:

bubuko.com,布布扣
<TreeView Grid.Row="1" Name="tvProperty">
            <TreeView.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFF05F5F" Offset="0"/>
                            <GradientStop Color="#FFF0A3A3" Offset="1"/>
                        </LinearGradientBrush>
                    </TreeView.Background>
                    <TreeView.ItemTemplate>
                        <HierarchicalDataTemplate DataType="{x:Type local:PropertyNodeItem}" ItemsSource="{Binding Path=Children}">
                            <StackPanel Orientation="Horizontal">
                                <Image VerticalAlignment="Center" Source="{Binding Icon}" Width="16px" Height="16px" Margin="0,0,2,2"/>
                                <TextBlock VerticalAlignment="Center" Text="{Binding DisplayName}" Foreground="White" FontSize="14"/>
                                <StackPanel.ToolTip>
                                    <TextBlock VerticalAlignment="Center" Text="{Binding Name}" TextWrapping="Wrap" MaxWidth="200px" FontSize="14"/>
                                </StackPanel.ToolTip>
                            </StackPanel>
                        </HierarchicalDataTemplate>
                    </TreeView.ItemTemplate> </TreeView>
bubuko.com,布布扣

建一个PropertyNodeItem类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace RunTrack.model
{
    internal class PropertyNodeItem
    {
        public string Icon { get; set; }
        public string DisplayName { get; set; }
        public string Name { get; set; }
        public List<PropertyNodeItem> Children { get; set; }
        public PropertyNodeItem()
        {
            Children = new List<PropertyNodeItem>();
        }
    }
}

 在xaml.cs文件中添加方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
private void ShowTreeView()
        {
            List<PropertyNodeItem> listItem = new List<PropertyNodeItem>();
            PropertyNodeItem mainNode = new PropertyNodeItem()
            {
                Icon=FLODER_ICON,
                DisplayName="功能菜单",
                Name="主目录--功能菜单"
            };
             
            PropertyNodeItem systemNode = new PropertyNodeItem()
            {
                Icon = FLODER_ICON,
                DisplayName="系统设置",
                Name="当前菜单--系统设置"
            };
            PropertyNodeItem pwdTag = new PropertyNodeItem()
            {
                Icon=LEAF_ICON,
                DisplayName="密码修改",
                Name="当前选项--密码修改"
            };
            systemNode.Children.Add(pwdTag);
            mainNode.Children.Add(systemNode);
            listItem.Add(mainNode);
            this.tvProperty.ItemsSource = listItem;
        }

 窗体初始化时调用改方法,便能显示出树状菜单

bubuko.com,布布扣

wpf treeview,布布扣,bubuko.com

wpf treeview

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/zaqn/p/3778739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!