相关疑难解决方法(0)

在具有超过1000个图像项的WPF ListBox中,缩放图像变慢

在开发照片查看器应用程序时遇到了问题.我使用ListBox来显示图像,它包含在ObservableCollection中.我将ListBox的ItemsSource绑定到ObservableCollection.

  <DataTemplate DataType="{x:Type modeldata:ImageInfo}">
        <Image 
            Margin="6"
            Source="{Binding Thumbnail}"
            Width="{Binding ZoomBarWidth.Width, Source={StaticResource zoombarmanager}}"
            Height="{Binding ZoomBarWidth.Width, Source={StaticResource zoombarmanager}}"/>
  </DataTemplate>

<Grid DataContext="{StaticResource imageinfolder}">
    <ScrollViewer
        VerticalScrollBarVisibility="Auto" 
        HorizontalScrollBarVisibility="Disabled">
        <ListBox Name="PhotosListBox"
            IsSynchronizedWithCurrentItem="True"
            Style="{StaticResource PhotoListBoxStyle}" 
            Margin="5"
            SelectionMode="Extended" 
            ItemsSource="{Binding}" 
           />
    </ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

我还使用滑块绑定ListBox中的Image'height.(滑块的Value也绑定到zoombarmanager.ZoomBarWidth.Width).但我发现如果集合变得更大,例如:包含超过1000个图像,如果我使用滑块来改变iamges的大小,它会变得有点慢.我的问题是.1.为什么变慢?变得它试图缩放每个图像,或者只是因为通知("宽度")被调用超过1000次.2.有没有什么方法可以解决这类问题并加快速度.

PhotoListBoxStyle是这样的:

    <Style~~ TargetType="{x:Type ListBox}" x:Key="PhotoListBoxStyle">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBox}" >
                    <WrapPanel 
                        Margin="5" 
                        IsItemsHost="True" 
                        Orientation="Horizontal" 
                        VerticalAlignment="Top"                             
                        HorizontalAlignment="Stretch" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style~~>
Run Code Online (Sandbox Code Playgroud)

但是如果我使用上面的Style,我必须在ListBox之外使用ScrollViewer,否则我不知道如何获得平滑的滚动滚动条并且wrappanel似乎没有默认的滚动条.有人帮吗?据说滚动查看器的列表框性能不佳.

wpf performance listbox image

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

image ×1

listbox ×1

performance ×1

wpf ×1