blawford
blawford

Reputation: 465

Spacing between ListItems on Horizontal Stackpanel

How do I control the amount of space between items coming from the Biding 'Shorthand'? At the moment I have gaps between which seem to be dependent on the size of the value of 'Shorthand' itself (so if the value is 1 character the gap between it and the next value is bigger compared to if the value is 2 characters long).

I have tried putting the margin and padding to zero in various places to no avail.

<ListView ItemsSource="{Binding Rounds}" IsItemClickEnabled="False" ItemClick="ItemView_ItemClick" ContinuumNavigationTransitionInfo.ExitElementContainer="True">
    <ListView.ItemTemplate>
        <DataTemplate >
            <StackPanel>
                <TextBlock Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}">
                    <Run Text="Round "/>
                    <Run Text="{Binding RoundNumber}" />
                </TextBlock>
                <ListView ItemsSource="{Binding Formations}" >
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Shorthand}"  Style="{ThemeResource ListViewItemTextBlockStyle}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Upvotes: 3

Views: 1714

Answers (2)

ordnerEnterprise
ordnerEnterprise

Reputation: 11

The first occurrence of ItemView of ListView is defined inline. So when ItemSource is set, the ItemTemplate is applied to EVERY item.

ListView.ItemTemplate encompassing Binding Shorthand. Place it in a Grid and define Grid.ColumnDefinitions to Width="Auto" or "*" for DataTemplate.

The StackPanel may help position it better. You will have to adjust Grid defs to your display requirements needed.

   <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" VerticalAlignment="Top" Margin="10,0,0,0">
                <TextBlock Text="{Binding Shorthand}"  Style="{ThemeResource ListViewItemTextBlockStyle}" />
            </StackPanel>
        </Grid>
    </DataTemplate>

Upvotes: 0

Romasz
Romasz

Reputation: 29792

I'm not sure where in the Template the margin/padding is set. As a workaround you may try to set a negative Margin to your ItemContainerStyle:

<ListView Name="myList">
     <ListView.ItemContainerStyle>
          <Style TargetType="ListViewItem">
              <Setter Property="Margin" Value="0,0,0,-20" />
          </Style>
     </ListView.ItemContainerStyle>
// rest of the code

Upvotes: 3

Related Questions