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
Don't assume shared understanding  25 Jan 2026
Old blog posts, restored  26 Oct 2025
Better Table Tests in Go  21 Oct 2025
Error assertions  26 Apr 2025
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
Archives
July 2011
2011