Quick Tip #2 – Stretching the ItemContainter of ListView

Suppose you have a data template for a Listview. It so happens that the Grid does not fill the whole list view. Your content seems to be left aligned.

Solution: You  need to set the ItemContainerStyle for the ListView

<ListView x:Name="InviteLV" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch">
<Grid MinHeight="60" HorizontalAlignment="Stretch" >
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<StackPanel HorizontalAlignment="Stretch" Margin="10,0,20,0">
<TextBlock Text="{Binding InviteName}" Foreground="Black" FontSize="26"/>
<TextBlock Text="{Binding InviteEmail}" Foreground="Black" FontSize="26"/>
<Button Grid.Column="1" BorderThickness="0" Width="50" Height="50" Margin="0">
<ImageBrush Stretch="Fill" ImageSource="Assets/Images/theme1_but_cancel_normal.png"/>

<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s