Your template seems pretty minimal, but I'm assuming you're just getting started, but this will help you get started with using ScaleTransform, not for animating the width.
ScaleTransform can be applied to the RenderTransform of either the button itself or just the border of your template. It could be a TransformGroup if you want to do more than just scale (i.e., a Compound transformation consisting of other trunks, such as Translation, Skew), but to make it simple and for example, something like the following applies one ScaleTransform value to Button:
<Button Template="{StaticResource IconButton}" Name="btnExit"> <Button.RenderTransform> <ScaleTransform ScaleX="1.0" ScaleY="1.0"></ScaleTransform> </Button.RenderTransform> <Image Source="Images/Exit.png" /> </Button>
or this applies to the ControlTemplate border:
<ControlTemplate x:Key="IconButton" TargetType="Button"> <Border Background="Blue" x:Name="render"> <Border.RenderTransform> <ScaleTransform ScaleX="1.0" ScaleY="1.0"></ScaleTransform> </Border.RenderTransform> <ContentPresenter Height="80" Width="80" /> </Border> ... ...
Then you want to change the MouseEnter trigger to target this property, and for width you want to target the ScaleX ScaleTransform property. The following storyboard will scale the button 2.5 times in the X direction (add TargetName="render" to <Storyboard... if you decide to apply the transformation to the border, as opposed to the button).
<EventTrigger RoutedEvent="Mouse.MouseEnter"> <BeginStoryboard> <Storyboard TargetProperty="RenderTransform.ScaleX"> <DoubleAnimation To="2.5" Duration="0:0:0.2" /> </Storyboard> </BeginStoryboard> </EventTrigger>
If you must use a TransformGroup with multiple transforms, you must change the TargetProperty value to something like RenderTransform.(TransformGroup.Children)[0].ScaleX , assuming ScaleTransform is the first child of the group.
This should make you work and work with what you need, and you can take it wherever you want ...
NTN
Simon fox
source share