首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Silverlight 4:树形视图/层次结构数据模板/ AutoExpand问题

Silverlight 4:树形视图/层次结构数据模板/ AutoExpand问题
EN

Stack Overflow用户
提问于 2011-07-06 18:13:18
回答 2查看 2.5K关注 0票数 0

我在我的silverlight应用程序中有一个treeview控件,它使用2个HierarchicalDataTemplate以所需的格式显示数据。我想让这个树在第一次打开时自动展开(最好是一个代码片段,我可以随时调用它)。

对给定代码的任何替代方案也将受到欢迎。

代码语言:javascript
运行
复制
<sdk:TreeView x:Name="tvPageManager" Style="{StaticResource PageManagerStyle}"                                       
                        ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto">
                        <sdk:TreeView.ItemTemplate>
                            <sdk:HierarchicalDataTemplate ItemsSource="{Binding KeyPoints, Mode=TwoWay}">
                                <StackPanel Orientation="Horizontal">
                                    <ToolTipService.ToolTip>
                                        <ToolTip Content="{Binding PageName}" Style="{StaticResource ToolTipStyle}"/>
                                    </ToolTipService.ToolTip>
                                    <Image x:Name="imgPageIcon" Source="{Binding PageIconImage}" Style="{StaticResource PageIconStyle}" Tag="{Binding BurstPageId, Mode=TwoWay}" />
                                    <TextBlock x:Name="tbkLiteralTextPage" Text="Page " Style="{StaticResource PageNameLiteralTextBlockStyle}" />
                                    <TextBox x:Name="tbPageName" Text="{Binding PageName, Mode=TwoWay}" Style="{StaticResource PageNameTextBoxStyle}" />
                                </StackPanel>
                                <sdk:HierarchicalDataTemplate.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <Image x:Name="imgKeypointIcon" Source="../Assets/Images/bullet_yellow.png" Style="{StaticResource KeypointIconStyle}"/>
                                            <TextBlock x:Name="tbkKeypointTitle" Text="{Binding Title, Mode=TwoWay}" Style="{StaticResource KeypointNameTextBlockStyle}"  />
                                            <StackPanel x:Name="spnlMoveImages" Orientation="Horizontal" HorizontalAlignment="Right" Width="30">
                                                <Image x:Name="imgMoveUp" Source="../Assets/Images/up_arrow.png" Style="{StaticResource MoveIconsStyle}" Tag="{Binding KeyPointId}"/>
                                                <Image x:Name="imgMoveDn" Source="../Assets/Images/down_arrow.png" Style="{StaticResource MoveIconsStyle}" Tag="{Binding KeyPointId}"/>
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </sdk:HierarchicalDataTemplate.ItemTemplate>
                            </sdk:HierarchicalDataTemplate>
                        </sdk:TreeView.ItemTemplate>
                    </sdk:TreeView>

此控件绑定到BurstPage类的可观察列表。完整的数据结构是as;

父元素是包含1到n个关键点对象的突发对象,任何给定的BurstPage都可以包含1到n个关键点对象。

BurstPage.Name (说1) Keypoint.Name (说A) Keypoint.Name (说B) Keypoint.Name (说C) BurstPage.Name (说2) BurstPage.Name (说3) Keypoint.Name (说D) Keypoint.Name (说E)

EN

回答 2

Stack Overflow用户

发布于 2011-07-06 19:48:31

我感觉你的帖子里少了很多代码……

但我认为您可能会发现以下内容很有用:one-more-platform-difference-more-or-less-tamed

它有一些很好的指针,告诉你如何绑定像treeview这样的控件,并在代码中使用它们。

票数 0
EN

Stack Overflow用户

发布于 2011-07-07 14:18:42

您说得对,XAML最初只会扩展树,而添加我使用的新节点;

代码语言:javascript
运行
复制
private void ExpandNode()
{
    if (branchSelector < 1)
        return;

    TreeViewItem item = null;
    int itemAtIndex = 0;

    //Update tree layout
    this.tvName.UpdateLayout();

    foreach (var branch in this.tvName.Items)
    {
        item = (this.tvName.GetContainerFromItem(this.tvName.Items[itemAtIndex]) as TreeViewItem);
        if (item != null && item.HasItems)
        {
            if ((branch as Model.BranchBusinessObject).Id== branchSelector && (!item.IsExpanded))
                item.IsExpanded = true;
        }
        itemAtIndex++;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6594758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档