【发布时间】:2011-09-27 15:59:34
【问题描述】:
我在 Silverlight 4 中使用分层树视图。这棵树可以经常清除和重建,具体取决于用户的操作。发生这种情况时,默认情况下树是折叠的,从用户的角度来看这可能很烦人。
所以,我想以某种方式保存哪些节点已展开,以便在清除并重新加载树后恢复其可视状态。
我的树视图是这样实现的:
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:controls2="clr-namespace:System.Windows;assembly=System.Windows.Controls"
<controls:TreeView x:Name="Tree"
ItemsSource="{Binding Source={StaticResource ViewModel}, Path=TreeStructure, Mode=OneWay}"
ItemTemplate="{StaticResource hierarchicalTemplate}" />
<controls2:HierarchicalDataTemplate x:Key="hierarchicalTemplate" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Value.DisplayName}">
</controls2:HierarchicalDataTemplate>
我的树视图的 ItemsSource 绑定在 ObservableCollection TreeStructure 上;
Node 是一个看起来像这样的包装类:
public class Node
{
public object Value { get; private set; }
public ObservableCollection<Node> Children { get; private set; }
public Node(object value)
{
Value = value;
Children = new ObservableCollection<Node>();
}
}
相当标准的东西。我看到了一些 WPF 的解决方案,但我可以找到 Silverlight 树视图的任何东西......
有什么建议吗?
谢谢!
【问题讨论】:
标签: c# silverlight silverlight-4.0 silverlight-toolkit