2014-09-02 81 views
0

我在我的WPF應用程序定義了以下列表框:滾動在列表框鼠標滾輪與修改ItemsPanel

<ListBox DockPanel.Dock="Bottom" Height="105" Name="ThumbnailsList" Background="#80FFFFF0" 
     SelectionChanged="ThumbnailsList_SelectionChanged"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <VirtualizingStackPanel Orientation="Horizontal"/> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox> 

我想改變ItemsPanel使用VirtualizingStackPanel性能和改變列表框的方向(部分註釋掉) - ListBoxItems是縮略圖圖像。但是,這會導致我無法使用鼠標滾輪滾動列表框項目。

是否有任何解決方案來保持此自定義,但有鼠標滾動功能?

由於提問者葉蘭,添加項目的代碼如下:

foreach (string filename in Images) 
{ 
    Image img = new Image(); 
    BitmapImage bmp = new BitmapImage(); 
    try 
    { 
     using (FileStream stream = File.OpenRead(filename)) 
     { 
      bmp.BeginInit(); 
      bmp.CacheOption = BitmapCacheOption.OnLoad; 
      bmp.DecodePixelHeight = 75; 
      bmp.StreamSource = stream; 
      bmp.EndInit(); 
     } 
    } 
    catch (Exception ex) 
    { 
     //commented out 
    } 

    Border b = new Border(); 
    b.BorderBrush = Brushes.AntiqueWhite; 
    b.BorderThickness = new Thickness(1); 
    b.Child = img; 
    b.Effect = ef; //this is System.Windows.Media.Effects.DropShadowEffect 
    img.SnapsToDevicePixels = true; 
    img.Source = bmp; 
    img.Height = 75; 
    img.ToolTip = filename.Substring(lastSlash + 1); 
    ThumbnailsList.Items.Add(b); 
} 
+0

發佈listboxitem – 2014-09-02 18:35:55

回答

0

你試過設置HorizontalScrollBarVisibilityVisible

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Visible"> 
+0

是的,但這並沒有幫助。謝謝,不過。 – 2014-09-10 06:43:37