【发布时间】:2014-09-02 18:20:29
【问题描述】:
我在我的 WPF 应用程序中定义了以下列表框:
<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);
}
【问题讨论】:
-
发布列表框项