5
votes

I am using a WrapGrid as itemscontrol in a ListView to present items horizontally with following XAML code (WinRT)

<ItemsPanelTemplate >
    <WrapGrid x:Name="ContentGrid" MinWidth="200" MinHeight="0" VerticalAlignment="Top"   HorizontalAlignment="Center"   Orientation="Horizontal" Margin="0,0,0,5" >                                     
    </WrapGrid>
</ItemsPanelTemplate>

Now how can i stretch items horizontally when the width is more than MinWidth and No More items can be added Horizontally. (All the items are aligned to center and there are lots of space in both sides horizontally)

<DataTemplate x:Key="CustomChildItemTemplete">
   <Grid Background="Red">
   </Grid>
</DataTemplate >

More Details: When the listview width is Around 800 (approx) it is showing 4 items horizontal (as minimum item width is 200) but if the width is 900 (4 items visible) and blank space (50 px) is in Right and Left of the itemscontrol, how can i remove this blank space by increasing the item width (simply item width must be 225 when listview width is 900)

1
I don't understand your problem very well. Maybe a screenshot of your result could be usefull ? - Nicolas Voron
Is this dynamic (the size of your ItemsControl change, or it's automatically set by the layout), or do you set the width or your itemsControl yourself ? - Nicolas Voron
@NicolasVoron, automatically set by the layout - VibeeshanRC

1 Answers

3
votes

The Easiest way is to bind MinWidth like this :

<ItemsControl x:Name="MyItemsControl">
  <ItemsPanelTemplate >
      <WrapGrid x:Name="ContentGrid" MinWidth="{Binding Path=Width,  MinWidth="{Binding RelativeSource={RelativeSource Mode=Self}, Converter={StaticRessource Myconverter}, ConverterParameter=[Here Nb of object that you want in one line]}" MinHeight="0" VerticalAlignment="Top"   HorizontalAlignment="Center"   Orientation="Horizontal" Margin="0,0,0,5" >                                     
      </WrapGrid>
  </ItemsPanelTemplate>
</ItemsControl>

And the converter just divide the width of your itemsControl by the parameter (Nb of object that you want in one line). So the objects are automatically at the size that you want !