0

在我的 WPF 应用程序中,如果我打开其中一个树视图项以显示所有子项,它会发生连锁事件并慢慢开始打开所有父项。例如,如果我打开红色,它会慢慢打开蓝色,直到它们都打开;

我的树视图代码;

<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; }
}
4

2 回答 2

0

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

于 2012-08-05T14:59:47.020 回答
0

事实证明我们必须改变;

VirtualizingStackPanel.VirtualizationMode="Recycling"

VirtualizingStackPanel.VirtualizationMode="Standard"
于 2012-08-22T21:29:37.497 回答