title: How to have buttons with the same width inside a ListView/WrapPanel?
body: <p>I have a ListView that shows a list of buttons inside a WrapPanel. The text inside the buttons may vary so the width of the buttons may also vary.</p>
  
  <p>I'd like to have all the buttons to have same width, meaning I want all the buttons to have the width of the larger button inside the WrapPanel. Is there a way to do that?</p>
  
  <p>Here's my ListView:</p>
  
  <pre><code>&lt;ListView Margin="8 10 8 8"
                        VerticalAlignment="Top"
                        ScrollViewer.CanContentScroll="True"
                        Background="Transparent"
                        x:Name="ResourcesList"
                        BorderThickness="0"
                        ItemContainerStyle="{DynamicResource LvItemStyle}"
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ItemsSource="{Binding CadResource.Values}"&gt;
                  &lt;ListView.ItemsPanel&gt;
                      &lt;ItemsPanelTemplate&gt;
                          &lt;WrapPanel HorizontalAlignment="Left" /&gt;
                      &lt;/ItemsPanelTemplate&gt;
                  &lt;/ListView.ItemsPanel&gt;
                  &lt;ListView.ItemTemplate&gt;
                      &lt;ItemContainerTemplate&gt;
                          &lt;Button Content="{Binding ResourceAlias.Value}"
                                  x:Name="ResourceButton"
                                  Command="{Binding ElementName=ResourcesList, Path=DataContext.SelectResourceCommand}"
                                  CommandParameter="{Binding}"
                                  VerticalContentAlignment="Stretch"
                                  BorderThickness="0"
                                  Margin="2"
                                  MinWidth="75"
                                  Template="{DynamicResource ResourceButtonTemplate}"
                                  Foreground="{DynamicResource ResouceAliasText}"
                                  Background="{Binding ResourceAlias.BackColor, Mode=TwoWay, Converter={converter:StringFormatConverter}}"&gt;
                              &lt;Button.ContextMenu&gt;
                                  &lt;ContextMenu Name="ContextMenu"
  
                                               ItemsSource="{Binding ContextMenu}"
                                               ItemContainerStyle="{StaticResource MenuItemStyle}" /&gt;
                              &lt;/Button.ContextMenu&gt;
                          &lt;/Button&gt;
                      &lt;/ItemContainerTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
              &lt;/ListView&gt;
  </code></pre>
  
  <p>And here's the template for the button that I'm using:</p>
  
  <pre><code>&lt;ControlTemplate x:Key="ResourceButtonTemplate"
                       TargetType="{x:Type ButtonBase}"&gt;
          &lt;Border x:Name="border"
                  Background="{DynamicResource ResourceButtonBackground}"
                  BorderThickness="1"
                  Height="20"
                  BorderBrush="{DynamicResource ResourceButtonBorder}"
                  SnapsToDevicePixels="True"&gt;
              &lt;Border BorderThickness="0 1 0 0"
                      Background="Transparent"
                      BorderBrush="{DynamicResource ResourceHighlight}"&gt;
                  &lt;Grid&gt;
  
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto" /&gt;
                          &lt;ColumnDefinition Width="*" /&gt;
                          &lt;ColumnDefinition Width="Auto" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
  
                      &lt;images:ResourceSquare Fill="{TemplateBinding Background}"
                                             Grid.Column="0"
                                             Style="{StaticResource ViewBoxStyleChildWindow13X13}"
                                             x:Name="ResourceSquare"
                                             HorizontalAlignment="Left"
                                             Margin="3 2 0 2" /&gt;
  
                      &lt;images:ResourceTriangle Fill="{TemplateBinding Background}"
                                               Grid.Column="0"
                                               Style="{StaticResource ViewBoxStyleChildWindow13X13}"
                                               x:Name="ResourceTriangle"
                                               Visibility="Collapsed"
                                               HorizontalAlignment="Left"
                                               Margin="3 2 0 2" /&gt;
  
                      &lt;ContentPresenter x:Name="contentPresenter"
                                        Grid.Column="1"
                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                        Content="{TemplateBinding Content}"
                                        ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                        Focusable="False"
                                        TextBlock.FontSize="{Binding FontSize}"
                                        Margin="7 0 7 0"
                                        RecognizesAccessKey="True"
                                        HorizontalAlignment="Center"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /&gt;
  
                      &lt;images:ResourceConnected Fill="{DynamicResource IconToolbar}"
                                                Grid.Column="2"
                                                Style="{StaticResource ViewBoxStyleChildWindow10X10}"
                                                HorizontalAlignment="Right"
                                                VerticalAlignment="Top" /&gt;
                  &lt;/Grid&gt;
              &lt;/Border&gt;
          &lt;/Border&gt;
          &lt;ControlTemplate.Triggers&gt;
              &lt;DataTrigger Binding="{Binding IsSelected.Value}"
                           Value="True"&gt;
                  &lt;Setter TargetName="border"
                          Property="Background"
                          Value="{DynamicResource ListSelectedLine}" /&gt;
                  &lt;Setter TargetName="border"
                          Property="BorderBrush"
                          Value="{DynamicResource BorderHighLight}" /&gt;
              &lt;/DataTrigger&gt;
              &lt;Trigger Property="Button.IsDefaulted"
                       Value="True"&gt;
                  &lt;Setter Property="BorderBrush"
                          TargetName="border"
                          Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="IsMouseOver"
                       Value="True"&gt;
                  &lt;Setter Property="Background"
                          TargetName="border"
                          Value="{DynamicResource CadMouseOver}" /&gt;
              &lt;/Trigger&gt;
          &lt;/ControlTemplate.Triggers&gt;
      &lt;/ControlTemplate&gt;
  </code></pre>