フォトビューアアプリケーションを開発するときに問題が発生しました。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>
また、リストボックスの画像の高さをスライダーでバインドします(スライダーの値もzoombarmanager.ZoomBarWidth.Widthにバインドします)。しかし、コレクションが大きくなると、次のようになります。1000を超える画像が含まれている場合、スライダーを使用して画像のサイズを変更すると、少し遅くなります。私の質問はです。1.なぜ遅くなるのですか?すべての画像をズームしようとするか、notify( "Width")が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~~>
ただし、上記のスタイルを使用する場合は、ListBoxの外部でScrollViewerを使用する必要があります。そうしないと、スムーズにスクロールするスクローラーバーを取得する方法がわからず、ラップパネルにデフォルトのスクローラーバーがないようです。誰か助けますか?scrollviewerを使用したリストボックスのパフォーマンスが低いと言われています。