TreeViewItem像链式事件一样扩展

时间:2012-08-05 14:01:22

标签: c# wpf xaml treeview

在我的WPF应用程序中,如果我打开其中一个treeviewitems以显示所有子项,它将继续链事件并慢慢开始打开所有父项。例如,如果我打开红色,它会慢慢打开蓝色,直到它们全部打开;

我的TreeView代码;

<TreeView x:Name="tvTagList" Margin="15, 40, 15, 50" SelectedItemChanged="tvTagList_SelectedTagChanged" ItemsSource="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{x:Null}" BorderBrush="{DynamicResource ExtryzeAccentBrushSecondary}" BorderThickness="2" ScrollViewer.CanContentScroll="True" Foreground="White"
                                  VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type  DataBind:TagClass}" ItemsSource="{Binding Children}" >
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                <TextBlock Text="{Binding TagClassMagic}" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type DataBind:TagEntry}">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                <TextBlock Text="{Binding TagFileName}" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>

我的课程;

public class TagClass
{
    public string TagClassMagic { get; set; }
    public ITagClass RawClass { get; set; }
    public List<TagEntry> TagEntries = new List<TagEntry>();

    public IList Children
    {
        get
        {
            return new CompositeCollection()
                {
                    new CollectionContainer() { Collection = TagEntries }
                };
        }
    }

}
public class TagEntry
{
    public string TagFileName { get; set; }
    public ITagEntry RawTag { get; set; }
}

2 个答案:

答案 0 :(得分:0)

我认为这是因为Children每次返回一个新的CompositeCollection,默认情况下可以扩展。请尝试直接返回TagEntries或仅在第一时间返回新的CompositeCollection

答案 1 :(得分:0)

原来我们不得不改变;

VirtualizingStackPanel.VirtualizationMode="Recycling"

VirtualizingStackPanel.VirtualizationMode="Standard"