0

I have WrapPanel where I want to add images that are created runtime. Using an ItemsControl, the functionality works ok, but the images are stretched to fill the WrapPanel's width. Attempting to set the size of the images (which are all 50x50) doesn't help. Here is my xaml code:

    <ItemsControl Grid.Row="2" Grid.Column="1" x:Name="ImagesWrapPanel" ItemsSource="{Binding CurrentCommentThumbnails}" Margin="5,5,5,5" >
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel />
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
  <ItemsControl.ItemTemplate>
    <DataTemplate>
        <Image Width="50" Height="50" HorizontalAlignment="Left" VerticalAlignment="Top" MaxWidth="50" MaxHeight="50"/>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>

Putting the Image control inside a Grid and setting the size properties for the Grid component doesn't help either. What am I missing here?

1 Answers1

0

try adding this code to ItemsControl:

  <ItemsControl.ItemContainerStyle>
    <Style TargetType="ContentPresenter">
      <Setter Property="Width" Value="50"/>
    </Style>
  </ItemsControl.ItemContainerStyle>
Bizhan
  • 16,157
  • 9
  • 63
  • 101