【发布时间】:2012-01-27 14:11:05
【问题描述】:
我已经开始使用来自 SO WPF: arranging collection items in a grid 的示例开发我的代码。现在,为了获得单元格选择功能,我将每个 ItemsControl 重命名为 ListBox,因为 ListBox 是一个 ItemsControl(XAMl 有所简化):
<ListBox HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ItemsSource="{Binding YourItems}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column" Value="{Binding X}"/>
<Setter Property="Grid.Row" Value="{Binding Y}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Image RenderOptions.BitmapScalingMode="LowQuality" Source="{Binding ...ImageSource, Mode=OneWay}">
</Image>
</DataTemplate>
</ListBox.ItemTemplate>
网格填充了基于代码 here 的字形运行测试图像。
令人惊讶的是,它起作用了——有点。选择工作。但是,在 ItemsControl 的情况下,没有滚动条。一切都很好地缩放。当我把窗口缩小时,网格单元缩小了,图像也缩小了。当我把窗口放大时,一切都放大了。
现在,ListBox 并非如此。图像大小保持固定。如果窗口不够大,则有一个水平滚动条,当窗口不够大时,一些图像会被隐藏,用户需要向右滚动。
所以,我的问题是:如果一个 ListBox 是一个 ItemControl,为什么我的图像比例不一样?我应该怎么做才能纠正它?
【问题讨论】:
标签: wpf image listbox scaling itemscontrol