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

Download

Button Width

Next Post
Semantic Versioning  28 Jul 2011
Prior Post
VSGraph 0.3.22  22 Jun 2011
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
July 2011
2011