次のように、アプリケーションでカスタムボタンを作成します
<Button x:Class="MyApp.ButtonMainMenuSubCat"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="536">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Grid Name="gridParent">
<Image Name="imgTransparent" Source="/MyApp;component/Resources/LeftCategoryTransparent.png" Stretch="Fill" Margin="0,0,0,0" />
<Image Name="Part_Pressed" Source="/MyApp;component/Resources/PressedMainScreenSubMenu.png" Stretch="Fill" Margin="0,0,0,4" Visibility="Hidden"/>
<Image Name="Focused" Source="/MyApp;component/Resources/MainSubMenuFocus.png" Margin="-3,0,-3,3" Stretch="Fill" Visibility="Hidden" />
<Image Name="Seperator" Source="/MyApp;component/Resources/MainSubMenuSeperator.png" Margin="5,0,5,-1" Stretch="Uniform" VerticalAlignment="Bottom"/>
<TextBlock Name="lblTitle" Text="{TemplateBinding Content}" HorizontalAlignment="Left" Foreground="Gray" FontWeight="{TemplateBinding FontWeight}" FontSize="24" Margin="10" VerticalAlignment="Center" TextWrapping="WrapWithOverflow" TextAlignment="Left"/>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<!--<Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>-->
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="Focused" Property="Visibility" Value="Visible"/>
<Setter TargetName="lblTitle" Property="Foreground" Value="#f8cb1c" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
私のアプリケーションでは、Webサービスを呼び出し、アイテムの数に応じて、アイテムごとにボタンを作成し、最後にこれらのボタンをStackPanelに追加します。それはうまく機能します。Stakpanelのレイアウトは、スクリーンショットの左側にあります。ここで問題となるのは、画面解像度が異なる(1920 * 1200など)別のマシンでこのアプリケーションを実行すると、フォントサイズが小さすぎるように見えることです。なので、コンテナサイズが変わったらフォントサイズを調整したいです。1つのオプションはViewBoxを使用することですが、ViewBoxの場合、すべてのボタンのフォントサイズが異なるようで、TextWrappingは使用できません。
したがって、私の実際の要件は、TextWrappingを使用してテキストブロックのフォントサイズを増減し、フォントサイズをすべてのボタンで均等にする必要があることです。