Getting the content of a ListView cell to stretch to the size of the cell (WPF)

I currently in the process of building a Download Manager that uses WPF, as I am sick of large downloads timing out and not being resumable, and I have never been happy with any of the download managers out there. I want something SIMPLE, basic, you copy a Url in and it downloads it… reliably… perhaps sometimes at a limited download rate if I don’t want my bandwidth chewed all at once. I’ll probably post the result on CodePlex where it can be promptly lost in the sea of projects.

Anyway I was display a ListView of the files and I wanted a progress bar in one of the cells, but I couldn’t get it to stretch to the size of the cell, I always had to set the size of the progress bar… Which seems silly, because I would have thought that Stretch would be the default behaviour for a cell (I guess it was deemed the most common content would be text which you don’t want stretched you want left aligned). Anyway long and short of it is, it’s easily fixed thanks to an article by Ian Griffiths.

Example (repeated here for quick reference)

Add this Xaml to your ListView…

    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
  1. Leave a comment

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: