I have a problem autosizing the (Text)Content of my buttons.
This is the style of my Buttons. Nothing special but notice the TextWrapping property!
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<TextBlock Text="{TemplateBinding Content}" TextWrapping="Wrap"/>
</Setter.Value>
</Setter>
</Style>
I defined a ItemTemplate based on my Buttons:
<DataTemplate x:Key="MyItemTemplate">
<Button Content="{Binding Content}" Command="{Binding Command}" FontWeight="Bold" FontSize="{Binding FontSize}"/>
</DataTemplate>
I am showing a list of items in with a ItemsControl with 3 columns:
<ItemsControl ItemsSource="{Binding MyItems}" ItemTemplate="{StaticResource MyItemTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Until this point, this is nothing special. But now, I want the FontSize of all my Buttons stretched to maximum possible, the item with the largest content allows (all items should have the same FontSize in the end).
I found a solution to calculate the needed size of a text. So I could calculate the maximum FontSize of a Button. But therefore I need the actual size of one of my Buttons (all have the same size).
I have not really an idea how to get the size and solve my problem. Would be great if anybody has an idea - or a totally different approach.