2

我一直在寻找加载缓慢的 wpf 表单的解决方案。似乎虚拟化应该可以帮助我,但我一定遗漏了一些东西。

我正在加载 35k 订单,加载需要 15 秒。我的猜测是虚拟化实际上并不适合我。

<UserControl x:Class="IntTranWin.Modules.Orders.OrderSummary.OrdersSummaryView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
  <ListView BorderThickness="0" Width="Auto" ItemsSource="{Binding Path=Orders.Items}" AlternationCount="2"
            IsSynchronizedWithCurrentItem="True" VirtualizingStackPanel.IsVirtualizing="True"
            VirtualizingStackPanel.VirtualizationMode="Recycling" ScrollViewer.IsDeferredScrollingEnabled="True">
    <ListView.ItemsPanel>
      <ItemsPanelTemplate>
        <VirtualizingStackPanel />
      </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <ListView.View>
      <GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Orders">
        <GridViewColumn Header="Number" DisplayMemberBinding="{Binding Path=OrderNumber}" Width="65" />
      </GridView>
    </ListView.View>
  </ListView>
</UserControl>
4

1 回答 1

0

谢谢你的建议。恐怕我提供的信息不完整。

我提供的 wpf 没有任何问题。问题在于禁用虚拟化的 GridView 的 ScrollViewer 样式。

<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}">
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type ScrollViewer}">
      <Grid Background="{TemplateBinding Background}">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <DockPanel Margin="{TemplateBinding Padding}">
          <ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"
                        Focusable="false">
            <Border CornerRadius="4" Background="{StaticResource DefaultedBorderBrush}" Padding="4" Margin="0,4,0,4">
              <GridViewHeaderRowPresenter Margin="2,0,2,0"
                                          Columns="{Binding Path=TemplatedParent.View.Columns,RelativeSource={RelativeSource TemplatedParent}}"
                                          ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}"
                                          ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}"
                                          ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector,RelativeSource={RelativeSource TemplatedParent}}"
                                          AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder,RelativeSource={RelativeSource TemplatedParent}}"
                                          ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu,RelativeSource={RelativeSource TemplatedParent}}"
                                          ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip,RelativeSource={RelativeSource TemplatedParent}}"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Border>

          </ScrollViewer>

          <ScrollContentPresenter Name="PART_ScrollContentPresenter" KeyboardNavigation.DirectionalNavigation="Local" />
        </DockPanel>

        <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1"
                   Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}"
                   Value="{TemplateBinding HorizontalOffset}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />

        <ScrollBar Name="PART_VerticalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}"
                   ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}"
                   Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />

      </Grid>
    </ControlTemplate>
  </Setter.Value>
</Setter>

我还没想出解决办法。我可能不得不放弃样式并换一种不同的外观。

于 2012-10-07T18:28:12.653 回答