views:

262

answers:

1

Hi,

What would be the best/right way to have a set of DataGrid columns have proportional width (Width="*"), but to have their MINIMUM width be at least the width of their content? At the moment, if I use Width="*", then the columns stay exactly proportional, but content gets cropped if the columns get too thin. If I use Width="Auto", then the columns size themselves perfectly to their content, but this makes them all different sizes.

What I want is really a combination of the two... like Width="*", MinWidth="Auto", so that when there's extra width the columns will all space out to equal widths, but when the grid is made smaller, the content never gets cropped.

Sadly, MinWidth="Auto" doesn't exist, so I guess I need to bind the column's MinWidth property, but it's hard to figure out exactly what I would bind it to.

So... how do I tell WPF "MinWidth = the width of the column's widest piece of content"?

Any help appreciated!

Thanks,

Andy

A: 

Set Width = "Auto" in XAML.

Then in the code:

MinWidth = ActualWidth
Width = new GridLength(1, GridUnitType.Star)
Anon