code_junkie

In a WPF ListBox with more than 1000 Image Items the Zoom Images become slow

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. <DataTemplate DataType="{x:Type modeldata:ImageInfo}">
  2. <Image
  3. Margin="6"
  4. Source="{Binding Thumbnail}"
  5. Width="{Binding ZoomBarWidth.Width, Source={StaticResource zoombarmanager}}"
  6. Height="{Binding ZoomBarWidth.Width, Source={StaticResource zoombarmanager}}"/>
  7. </DataTemplate>
  8.  
  9. <Grid DataContext="{StaticResource imageinfolder}">
  10. <ScrollViewer
  11. VerticalScrollBarVisibility="Auto"
  12. HorizontalScrollBarVisibility="Disabled">
  13. <ListBox Name="PhotosListBox"
  14. IsSynchronizedWithCurrentItem="True"
  15. Style="{StaticResource PhotoListBoxStyle}"
  16. Margin="5"
  17. SelectionMode="Extended"
  18. ItemsSource="{Binding}"
  19. />
  20. </ScrollViewer>
  21.  
  22. <Style~~ TargetType="{x:Type ListBox}" x:Key="PhotoListBoxStyle">
  23. <Setter Property="Foreground" Value="White" />
  24. <Setter Property="Template">
  25. <Setter.Value>
  26. <ControlTemplate TargetType="{x:Type ListBox}" >
  27. <WrapPanel
  28. Margin="5"
  29. IsItemsHost="True"
  30. Orientation="Horizontal"
  31. VerticalAlignment="Top"
  32. HorizontalAlignment="Stretch" />
  33. </ControlTemplate>
  34. </Setter.Value>
  35. </Setter>
  36. </Style~~>
  37.  
  38. <ListBox.ItemsPanel>
  39. <ItemsPanelTemplate>
  40. <WrapPanel Orientation="Horizontal"/>
  41. </ItemsPanelTemplate>
  42. </ListBox.ItemsPanel>
  43.  
  44. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
  45.  
  46. <ListBox.ItemsPanel>
  47. <ItemsPanelTemplate>
  48. <StackPanel>
  49. <StackPanel.LayoutTransform>
  50. <ScaleTransform
  51. ScaleX="{Binding Path=Value, ElementName=ZoomSlider}"
  52. ScaleY="{Binding Path=Value, ElementName=ZoomSlider}" />
  53. </StackPanel.LayoutTransform>
  54. </StackPanel>
  55. </ItemsPanelTemplate>
  56. </ListBox.ItemsPanel>
  57.  
  58. class PathToThumbnailConverter : IValueConverter {
  59. public int DecodeWidth {
  60. get;
  61. set;
  62. }
  63.  
  64. public PathToThumbnailConverter() {
  65. DecodeWidth = 200;
  66. }
  67.  
  68. public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
  69. var path = value as string;
  70.  
  71. if ( !string.IsNullOrEmpty( path ) ) {
  72.  
  73. FileInfo info = new FileInfo( path );
  74.  
  75. if ( info.Exists && info.Length > 0 ) {
  76. BitmapImage bi = new BitmapImage();
  77.  
  78. bi.BeginInit();
  79. bi.DecodePixelWidth = DecodeWidth;
  80. bi.CacheOption = BitmapCacheOption.OnLoad;
  81. bi.UriSource = new Uri( info.FullName );
  82. bi.EndInit();
  83.  
  84. return bi;
  85. }
  86. }
  87.  
  88. return null;
  89. }
  90.  
  91. public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
  92. throw new NotImplementedException();
  93. }
  94.  
  95. }
Add Comment
Please, Sign In to add comment