2

I want to Change the Height of the ItemContainer and not the Heightof the Item itself the Container is in a ListView

What I want to Change:

enter image description here

To Something like this:

enter image description here

The structur of the Code Looks like this:

 <ListView>
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding A}" Grid.Column="0"/>
                                    <TextBlock Text="{Binding B}" Grid.Column="1"/>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

Hope for some help

blueeyes
  • 59
  • 2
  • 10

1 Answers1

9

You need to change the MinHeight of all ListViewItem elements that appear in your ListView. You can achieve this by using a Style.

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="MinHeight" Value="0"/>
            <Setter Property="Padding" Value="6,3"/>
        </Style>
    </ListView.ItemContainerStyle>

    <TextBlock Text="Hello"/>
    <TextBlock Text="World"/>
</ListView>

Using Padding with this method is also a good idea as you do not want each list view item to be too thin.

Mike Eason
  • 9,525
  • 2
  • 38
  • 63
  • thanks for your quick anser but this doesn't work on my Items, i even set a minus value – blueeyes Nov 04 '15 at 15:48
  • Do you have any other styles that target `ListViewItem`? Is this example working in your project? Perhaps create a new project just to see if it works? – Mike Eason Nov 04 '15 at 16:35
  • Now I konw why it didn't work ... because of the DataTemplat i had but now the binding doesn't work could you help me here again the binding is to the `ItemsSource="{Binding Items}"` and in the `Textblocks` look like `Text="{Binding Name}"` and `Text="{Binding Adress}"` and both of them are in a Grid hope you can help me again ;) – blueeyes Nov 05 '15 at 07:33