繁体   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