On StackOverflow, I read an interesting WPF question:

Suppose you have a window with multiple buttons such as Ok/Cancel or Yes/No/Cancel.

All the buttons need to be the same width.

Several good answers had been given, but none mentioned the simplest technique - leveraging SharedSizeGroup to constrain Grid columns to the same width.

In my answer to the question, I wrote:

Another, perhaps simpler, way to do this is to use the SharedSizeGroup property on the ColumnDefinition and RowDefinition classes.

Columns (and Rows) in a WPF Grid can automatically resize to fit their contents - when SharedSizeGroup is used, columns with the same group name share their resizing logic.

There’s a simple XAML example included with my original answer - but for a fuller (interactive) solution, try the source code attached.

Comments

blog comments powered by Disqus