gpt4 book ai didi

WPF:列表框和虚拟化

转载 作者:行者123 更新时间:2023-12-02 00:44:11 25 4
gpt4 key购买 nike

  1. 我如何知道我的列表是否正在虚拟化?
  2. 如何使该代码段虚拟化?

    <ScrollViewer Grid.Column="1" Name="LogScroller">
    <r:NoInheritanceContentControl>
    <ListBox Background="Black" ItemsSource="{Binding Path=ActiveLog}" >
    <ListBox.ItemTemplate>
    <DataTemplate>
    <Grid Background="Black">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="200"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition></RowDefinition>
    <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <TextBlock Grid.Column="0" Grid.Row="0" Foreground="White">
    <TextBlock >Date:</TextBlock>
    <TextBlock Text="{Binding Path=LogDate}"/>
    </TextBlock>
    <TextBlock Grid.Column="1" Grid.Row="0" Foreground="White">
    <TextBlock >Severity:</TextBlock>
    <TextBlock Text="{Binding Path=Severity}"/>
    </TextBlock>
    <TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Foreground="LightGray" Text="{Binding Path=Message}"></TextBlock>
    </Grid>
    </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.Template>
    <ControlTemplate>
    <StackPanel Background="Black" IsItemsHost="True" >
    </StackPanel>
    </ControlTemplate>
    </ListBox.Template>
    </ListBox>
    </r:NoInheritanceContentControl>
    </ScrollViewer>

最佳答案

您的代码示例未虚拟化,因为您强制使用 StackPanel。您必须使用VirtualizingStackPanel

关于WPF:列表框和虚拟化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2143655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com