Nick
Nick

Reputation: 10499

Force ListViewItem to occupy all ListView width

I have a ListView and I want to add some children. I want that these ListViewItems (for example Border instances) have a Height of 25, and a Width equal to that of the ListView, even when I resize the ListView.

I try the following code to add 10 elements:

for (int i = 0; i < 10; i++)
{
    ListPsw.Items.Add(new Border 
    { 
        BorderThickness = new Thickness(2), 
        BorderBrush = Brushes.Black, 
        Margin = new Thickness(5),
        Height = 25
    });
}

and this is the result:

enter image description here

But I want something like this:

enter image description here


How can I do?

Upvotes: 2

Views: 330

Answers (1)

kmatyaszek
kmatyaszek

Reputation: 19296

You must set HorizontalContentAlignment property to Stretch.

<ListView Name="ListPsw" HorizontalContentAlignment="Stretch" />

Upvotes: 1

Related Questions