2012-01-27 52 views
0

我已经开始使用SO WPF: arranging collection items in a grid的示例开发我的代码。现在,为了获得小区选择能力,我改名每个的ItemsControl到列表框,因为列表框是-一个ItemsControl的(XAML略微简化):在WPF列表框中缩放图像

<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的情况下,没有滚动条。一切都很好。当我缩小窗口时,网格单元收缩,图像也缩小。当我把窗户放大时,一切都放大了。

现在,与列表框不是这种情况。图像大小保持不变。如果窗口不够大,则有一个水平滚动条,当窗口不够大时,一些图像被隐藏,用户需要向右滚动。

所以,我的问题是:如果列表框是一个ItemControl,为什么我的图像缩放比例不一样?我应该怎么做才能纠正它?

回答

1

这是因为ListBox和ItemsControl使用不同的样式。您可以轻松地将ItemControl的默认样式应用于您的ListBox:

<ListBox Style="{StaticResource ResourceKey={x:Type ItemsControl}}">