日期:2014-05-17  浏览次数:21093 次

[求助]wpf中TreeView的显示问题
想做一个基于WPF的目录树
具体的效果是这样的

每个TreeViewItem显示文件夹
分别显示图标、文件夹名称和当前文件夹的子文件夹个数

现在问题就是第三项显示“当前文件夹的子文件夹个数”这一项总是为0。(调试有数值,但界面显示0)
前台代码
<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:loc="clr-namespace:WpfApplication2"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TreeView>
            <loc:MyTreeViewItem x:Name="MyFiles">
                <loc:MyTreeViewItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Width="16" Height="16" Source="/WpfApplication2;component/Images/Folder.png" />
                        <TextBlock Text="我的文件"></TextBlock>
                        <TextBlock Text="{Binding Count}" Margin="5,0,0,0"></TextBlock>
                    </StackPanel>
                </loc:MyTreeViewItem.Header>
                <loc:MyTreeViewItem>
                    <loc:MyTreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Width="16" Height="16" Source="/WpfApplication2;component/Images/Folder.png" />