0

I am struggling with a ListView of many Buttons - I want to stretch the text of all buttons to the same size. I saw this answer for TextBlocks, but I need a solution for Buttons. I broke my problem down to this minimal example.

This is my template. I am stretching the Text of my Button with a ViewBox.

<DataTemplate x:Key="MyTemplate">
    <Button>
        <Button.Template>
            <ControlTemplate TargetType="Button">
                <Border BorderThickness="3" BorderBrush="Black" Margin="1,1,1,1">
                    <Viewbox Stretch="Uniform">
                        <TextBlock Text="{Binding Name}"/>
                    </Viewbox>
                </Border>
            </ControlTemplate>
        </Button.Template>
    </Button>
</DataTemplate>

I am using the template in a ItemsControl with a UniformGrid like this:

<ItemsControl ItemsSource="{Binding MyItems}" ItemTemplate="{StaticResource MyTemplate}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="4"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

The result of this combination is like this. Every Button is stretching the text different. enter image description here

But I want to stretch the Text of every button to the same FontSize. So the FontSize of my Buttons sould be the largest possible FontSize of all Buttons.

The result should look like this: enter image description here

Is there a way to reach this? I appreciate any help!

Community
  • 1
  • 1
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
  • 2
    https://stackoverflow.com/questions/15641473/how-to-automatically-scale-font-size-for-a-group-of-controls – d.moncada Apr 25 '16 at 21:07
  • I saw this answer already @d.moncada ... but this is only a solution for TextBlocks. I need a solution for Buttons. Do you have an idea how tu use this apporach to solve my problem? – Fruchtzwerg Apr 26 '16 at 15:03

0 Answers0