WPFでボタンのデフォルトのテキストラッピングスタイルを変更するにはどうすればよいですか?
次の明らかな解決策:
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
ここでは Textwrapping が設定可能なプロパティではないため、機能しません。
私が試してみると:
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<TextBlock Text="{Binding}" Foreground="White" FontSize="20" FontFamily="Global User Interface" TextWrapping="Wrap"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
コンパイラから価値のない応答が返されます。
Error 5 After a 'SetterBaseCollection' is in use (sealed), it cannot be modified.
ControlTemplate タグを削除すると、エラーが保持されます。
次の試行では、別のエラーが発生します。
<Setter Property="TextBlock">
<TextBlock Text="{Binding}" Foreground="White" FontSize="20" FontFamily="Global User Interface" TextWrapping="Wrap"/>
</Setter>
Error 5 The type 'Setter' does not support direct content.
ボタンごとにテキストの折り返しを個別に設定できることがわかりましたが、それはかなりばかげています。スタイルとしてはどうすればいいですか?魔法の言葉とは?
将来の参考のために、これらの魔法の言葉のリストはどこにありますか?セッターがどのプロパティを設定できるかを調べようとすると、MSDN エントリはほとんど役に立ちません。