簡體   English   中英

在具有修改后的ItemsPanel的ListBox中使用鼠標滾輪滾動

[英]Scrolling with mouse wheel in ListBox with modified ItemsPanel

我在WPF應用程序中定義了以下ListBox:

<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來提高性能,並更改ListBox的方向(注釋掉的部分)-ListBoxItems是縮略圖。 但是,這使我無法使用鼠標滾輪滾動瀏覽ListBox項。

有什么解決方案可以保留此自定義功能,但具有鼠標滾動功能?

按照eran的要求,添加項目的代碼如下:

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);
}

您是否嘗試過將HorizontalScrollBarVisibility設置為Visible

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Visible">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM