就是你讲的方法,开始是因为节点展开状态一直控制不好,后来改成双绑就可以了
- <c1:C1TreeView c1:C1NagScreen.Nag="True" x:Name="tree1" ItemExpanded="tree1_ItemExpanded">
- <c1:C1TreeView.ItemContainerStyle>
- <Style TargetType="c1:C1TreeViewItem">
- <Setter Property="IsExpanded" Value="{Binding IsExpd,Mode=TwoWay}"/>
- </Style>
- </c1:C1TreeView.ItemContainerStyle>
- <c1:C1TreeView.ItemTemplate>
- <c1:C1HierarchicalDataTemplate x:Name="treeTemplate" ItemsSource="{Binding Nodes}">
- <StackPanel Orientation="Horizontal">
- <Image HorizontalAlignment="Left" Width="14" Height="13" Source="***/treeNode.png" Stretch="Fill" Margin="0 0 5 0"/>
- <TextBlock Text="{Binding NodeName}"/>
- </StackPanel>
- </c1:C1HierarchicalDataTemplate>
- </c1:C1TreeView.ItemTemplate>
- </c1:C1TreeView>
复制代码
每次加载一级节点时,把存在下级节点的节点强制加一个名叫“loading...”的假子节点,在“tree1_ItemExpanded”方法中把节点下的内容替换为真实的子节点,同时加再下一级的假节点。 |