Juan Pablo Gomez
Juan Pablo Gomez

Reputation: 5534

XAML GridView Remove space between items

I have this GridView,

enter image description here

And want to remove spaces between items, I Try setting Marging and Padding to 0 as this:

           <GridView ItemsSource="{Binding ElementName=AprehenderPage,Path=DataContext.LecturasCorrectas}"
                  Margin="0"
                  Padding="0">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid Height="35" 
                          Margin="0" 
                          Padding="0">
                        <Image Source="{Binding Imagen}"
                               Margin="0"/>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>

But this does nothing.

How Can I do to remove those spaces?

or

What other control must I use?

Upvotes: 0

Views: 1821

Answers (2)

Jun
Jun

Reputation: 804

It looks like you might be using UWP rather than WPF as I don't think WPF GridView has an ItemsSource. If that's the case, then your margin is probably from GridViewItem:

GridViewItem (the container object) has Margin according to MSDN:

https://msdn.microsoft.com/en-us/library/windows/apps/mt299127.aspx

So you'll need to restyle the item like so:

    <Style x:Key="MyItem" TargetType="GridViewItem">
      <Setter Property="BorderThickness" Value="0"/>
      <Setter Property="Margin" Value="0"/>
      <Setter Property="Padding" Value="0"/>
    </Style>

And have a setter on your gridview for container style:    

<Setter Property="ItemContainerStyle" Value="{StaticResource MyItem}" />

Upvotes: 3

afr0
afr0

Reputation: 888

Try auto height.

<Grid Height="Auto" ...

Also you can have negative margins if need be

and margins like..

Margin ="-value"

Upvotes: 0

Related Questions