在推出照片查看器應用程序時遇到問題。 我使用ListBox來顯示包含在ObservableCollection中的圖像。 我將ListBox的ItemsSource綁定到ObservableCollection。在具有超過1000個圖像項目的WPF列表框中,縮放圖像變得很慢
<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>
我也綁定Image'height與滑塊列表框(滑塊的價值還結合zoombarmanager.ZoomBarWidth.Width)。 但是我發現如果集合變大,比如:包含超過1000個圖像,如果我使用滑塊來改變圖像的大小,它會變得有點慢。 我的問題是。 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~~>
但如果我使用上面的風格,我必須使用的ScrollViewer外列表框,否則我不知道如何獲得平滑滾動scrollerbar和wrappanel似乎有沒有默認的滾動條。任何人幫助?據說scrollviewer的listbox性能很差。
綁定每個圖像的高度/寬度是效率極其低下,只使用一個LayoutTransform在ItemsPanel(加答案,這個效果) 。 – user7116 2008-10-08 14:00:31