Buttonから派生したコントロールがあります。
public class ToolButton : Button
{
static ToolButton() {}
public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
}
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ToolButton), new UIPropertyMetadata(null));
}
そしてそのためのスタイル:
<Style TargetType="{x:Type wordplay:ToolButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type wordplay:ToolButton}">
<StackPanel Height="Auto" Orientation="Horizontal" Margin="4">
<Image Source="{TemplateBinding ImageSource}" Stretch="UniformToFill" />
<TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Left" Foreground="{DynamicResource TaskButtonTextBrush}" FontWeight="Bold" Margin="5,0,0,0" VerticalAlignment="Center" FontSize="12" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
次に、マウスホバーでTextBlockの幅をアニメーション化する必要があるため、ユーザーが画像だけでボタンをホバーすると、テキストが表示されます。また、ユーザーがマウスポインターを離すと、テキストは非表示になります。これをスタイルに設定して、どのToolButtonでも機能するようにします。問題は、ツールボタンの結果のサイズがわからないため、幅をアニメーション化できないことです。どうすればこれを達成できますか?