Unable to do annimation on transform group - wpf

How can I perform transforms animation on a UIElement?
The following code moves a rectangle via annimation but does not transform it when running animation.
I have looked at tutorials and am absolutely confused as to why the following XAML does not work:
XAML:
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Canvas.Top)"
From="20" To="73"
Duration="0:0:.15">
</DoubleAnimation>-->
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(SkewTransform.AngleX)"
From="0" To="-25"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(RotateTransform.Angle)"
From="0" To="-25"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(TranslateTransform.X)"
From="0" To="-40"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(TranslateTransform.Y)"
From="0" To="20"
Duration="0:0:.15">
</DoubleAnimation>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Canvas>
<Rectangle x:Name="FrontRectangle" Width="400" Height="246" Fill="Purple"
Canvas.Left="285" Canvas.Top="20" Panel.ZIndex="4" />
<Rectangle x:Name="RightRectangle" Width="100" Height="100" Fill="LightBlue"
RenderTransformOrigin="0.5,0.5" Canvas.Left="774" Canvas.Top="191" Panel.ZIndex="2">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="2.5"/>
<SkewTransform AngleX="60"/>
<RotateTransform Angle="-145"/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="LeftRectangle" Width="100" Height="100" Fill="LightGreen"
RenderTransformOrigin="0.5,0.5" Canvas.Left="99" Canvas.Top="191" Panel.ZIndex="2" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="2.5"/>
<SkewTransform AngleX="-60"/>
<RotateTransform Angle="145"/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="MidLeftRectangle" Width="350" Height="160" Fill="LightSeaGreen"
Canvas.Left="159" Canvas.Top="73" RenderTransformOrigin="0.5,0.5" Panel.ZIndex="3" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="-25"/>
<RotateTransform Angle="-25"/>
<TranslateTransform X="-40" Y="20"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="MidRightRectangle" Width="350" Height="160" Fill="LightCoral"
Canvas.Left="559" Canvas.Top="73" RenderTransformOrigin="0.5,0.5" Panel.ZIndex="3" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="25"/>
<RotateTransform Angle="25"/>
<TranslateTransform X="-40" Y="20"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Grid>
Code-behind:
private void OnSwipedLeft()
{
var visualState = "SwipeLeftState";
var success = VisualStateManager.GoToElementState(MyGrid, visualState, true);
Debug.Assert(success);
}

I had to insert a "(TransformGroup.Children)[some_index]" between RenderTransform and the actual type of transform.
<Grid x:Name="MyGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SwipeLeftGroup">
<VisualState x:Name="SwipeLeftState">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Canvas.Left)"
From="285" To="159"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Canvas.Top)"
From="20" To="73"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)"
From="0" To="-25"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"
From="0" To="-25"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
From="0" To="-40"
Duration="0:0:.15">
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="FrontRectangle"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"
From="0" To="20"
Duration="0:0:.15">
</DoubleAnimation>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Canvas>
<Rectangle x:Name="FrontRectangle" Width="400" Height="246" Fill="Purple"
Canvas.Left="290" Canvas.Top="20" Panel.ZIndex="4">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="RightRectangle" Width="100" Height="100" Fill="LightBlue"
RenderTransformOrigin="0.5,0.5" Canvas.Left="774" Canvas.Top="191" Panel.ZIndex="2">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="2.5"/>
<SkewTransform AngleX="60"/>
<RotateTransform Angle="-145"/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="LeftRectangle" Width="100" Height="100" Fill="LightGreen"
RenderTransformOrigin="0.5,0.5" Canvas.Left="99" Canvas.Top="191" Panel.ZIndex="2" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="2.5"/>
<SkewTransform AngleX="-60"/>
<RotateTransform Angle="145"/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="MidLeftRectangle" Width="350" Height="160" Fill="LightSeaGreen"
Canvas.Left="159" Canvas.Top="73" RenderTransformOrigin="0.5,0.5" Panel.ZIndex="3" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="-25"/>
<RotateTransform Angle="-25"/>
<TranslateTransform X="-40" Y="20"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle x:Name="MidRightRectangle" Width="350" Height="160" Fill="LightCoral"
Canvas.Left="559" Canvas.Top="73" RenderTransformOrigin="0.5,0.5" Panel.ZIndex="3" >
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="25"/>
<RotateTransform Angle="25"/>
<TranslateTransform X="-40" Y="20"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Grid>

Related

WPF Animation - Rotate elements on button click

I want to rotate two elements from 0 to angles: 1. Element (ClampL) 45 angle and 2. Element (ClampR) -45 Angle, but they should move together. The elements are 2 clamps which are open and when they grab something, they close and this process should happen on button click.
Here is my XAML:
<UserControl x:Class="WPF_AnimatedLift.View.Prozess"
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"
xmlns:local="clr-namespace:WPF_AnimatedLift.View" xmlns:viewmodel="clr-namespace:WPF_AnimatedLift.ViewModel"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="1000">
<Canvas x:Name="canvas" Margin="0,0,-163,-83">
<Path x:Name="ClampR" Fill="#FF000000" StrokeThickness="2.12787" Data="M 524.2207 473.57227 L 524.2207 563.57227 L 137.14258 563.57227 L 137.14258 652.14258 L 571.42773 652.14258 L 571.42773 563.57227 L 571.36328 563.57227 L 571.36328 473.57227 L 524.2207 473.57227 z " Height="68.668" Stretch="Fill" Width="80.734" Canvas.Left="411.375" Canvas.Top="339.125" >
<Path.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ClampR"
Storyboard.TargetProperty="LayoutTransform.(RotateTransform.Angle)"
From="0"
To="360"
Duration="0:0:5"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
<Path.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.265" ScaleX="0.265"/>
<SkewTransform/>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="-45"/>
<TranslateTransform/>
</TransformGroup>
</Path.LayoutTransform>
</Path>
<Path x:Name="ClampL" Fill="#FF000000" StrokeThickness="2.12787" Data="M 110 344.28516 L 110 434.28516 L 110 485.71484 L 110 522.85742 L 544.28516 522.85742 L 544.28516 434.28516 L 157.14258 434.28516 L 157.14258 344.28516 L 110 344.28516 z " Height="68.668" Stretch="Fill" Width="80.734" Canvas.Left="384.508" Canvas.Top="339.166">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.265" ScaleX="0.265"/>
<SkewTransform/>
<RotateTransform Angle="45"/>
<TranslateTransform/>
</TransformGroup>
</Path.RenderTransform>
</Path>
<Button Content="START" Canvas.Left="84" Canvas.Top="403" Width="106" Height="48" FontSize="30" FontWeight="Bold" Name="BtnStart" Command="{Binding ClickCommand, UpdateSourceTrigger=PropertyChanged}" >
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click"> //???
<BeginStoryboard Storyboard="{StaticResource Storyboard}" />
</EventTrigger>
</Button.Triggers>
</Button>
</Canvas>
<UserControl.DataContext>
<viewmodel:ProzessViewModel/>
</UserControl.DataContext>
</UserControl>
As you can see in code, I tried with Path.Trigger, DoubleAnimation, but it doesn't work, can someone help me?
Thank you.
Basically, in EventTrigger, you can only refer the elements that exist inside that FrameworkElement. The solution would be different depending on where you want to set EventTrigger.
1. Button
You can use EventTrigger in the Button, which is the source of Button.Click event, like the following. The elements are simplified to a minimum for brevity and the Storyboard.TargetProperty is modified to circumvent TransformGroup.
<Canvas x:Name="canvas">
<Path x:Name="ClampR"
Canvas.Left="411" Canvas.Top="339"
Width="80" Height="68"
Fill="Black"
Data="M 0,0 1,0 0,1 z" Stretch="Fill">
<Path.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.265" ScaleX="0.265"/>
<SkewTransform/>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="-45"/>
<TranslateTransform/>
</TransformGroup>
</Path.LayoutTransform>
</Path>
<Button x:Name="BtnStart"
Canvas.Left="84" Canvas.Top="403"
Width="106" Height="48"
Content="START">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ClampR"
Storyboard.TargetProperty="LayoutTransform.Children[2].Angle"
From="0" To="360"
Duration="0:0:5"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Canvas>
2. Canvas
As Button.Click is RoutedEvent and propagated to the root, you can use EventTrigger at parent level. In this case, at Canvas.Triggers.
<Canvas x:Name="canvas">
<Canvas.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ClampR"
Storyboard.TargetProperty="LayoutTransform.Children[2].Angle"
From="0" To="360"
Duration="0:0:5"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<Path x:Name="ClampR"
Canvas.Left="411" Canvas.Top="339"
Width="80" Height="68"
Fill="Black"
Data="M 0,0 1,0 0,1 z" Stretch="Fill">
<Path.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.265" ScaleX="0.265"/>
<SkewTransform/>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="-45"/>
<TranslateTransform/>
</TransformGroup>
</Path.LayoutTransform>
</Path>
<Button x:Name="BtnStart"
Canvas.Left="84" Canvas.Top="403"
Width="106" Height="48"
Content="START"/>
</Canvas>
3. Path
Unlike standard EventTrigger, EventTrigger of Microsoft.Xaml.Behaviors.Wpf is more robust and can refer other controls. Thus it can work in the Path.
Add xmlns:i="http://schemas.microsoft.com/xaml/behaviors" in header.
<Canvas x:Name="canvas">
<Path x:Name="ClampR"
Canvas.Left="411" Canvas.Top="339"
Width="80" Height="68"
Fill="Black"
Data="M 0,0 1,0 0,1 z" Stretch="Fill">
<i:Interaction.Triggers>
<i:EventTrigger SourceName="BtnStart" EventName="Click">
<i:ControlStoryboardAction>
<i:ControlStoryboardAction.Storyboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Rotation"
Storyboard.TargetProperty="(RotateTransform.Angle)"
From="0" To="360"
Duration="0:0:5"
RepeatBehavior="Forever"/>
</Storyboard>
</i:ControlStoryboardAction.Storyboard>
</i:ControlStoryboardAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<Path.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.265" ScaleX="0.265"/>
<SkewTransform/>
<RotateTransform x:Name="Rotation" CenterX="0.5" CenterY="0.5" Angle="-45"/>
<TranslateTransform/>
</TransformGroup>
</Path.LayoutTransform>
</Path>
<Button x:Name="BtnStart"
Canvas.Left="84" Canvas.Top="403"
Width="106" Height="48"
Content="START"/>
</Canvas>

Flicker on bars

I have the XAML code below but it's not smooth and creates flicker once in a while. How can i improve this in XAML? I have tried multiple solutions but it always seem to create flicker multiple times within a minute. Is this because of the frame rate of my monitor and the source code or? Please help. If you have examples on getting this smooth i would appreciate it.
<Window x:Class="BarsTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BarsTest"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Horizontal" Background="Black">
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform0" X="-160" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform1" X="160" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform2" X="480" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform3" X="800" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform4" X="1120" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform5" X="1440" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Height="1080" Width="160" Fill="White">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform6" X="1760" Y="0" />
</Rectangle.RenderTransform>
</Rectangle>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Name="myBeginStoryboard">
<Storyboard DesiredFrameRate="60">
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform0" Storyboard.TargetProperty="X" From="-160" To="160" Duration="0:0:0.5"/>
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform1" Storyboard.TargetProperty="X" From="0" To="320" Duration="0:0:0.5"/>
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform2" Storyboard.TargetProperty="X" From="160" To="480" Duration="0:0:0.5" />
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform3" Storyboard.TargetProperty="X" From="320" To="640" Duration="0:0:0.5" />
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform4" Storyboard.TargetProperty="X" From="480" To="800" Duration="0:0:0.5" />
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform5" Storyboard.TargetProperty="X" From="640" To="960" Duration="0:0:0.5" />
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform6" Storyboard.TargetProperty="X" From="800" To="1120" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</Grid>
</Window>
Br
ARUS

Animation border

I have border, that I want to animate by clicking button (name = "button1"). Button is outside. My code throws an exception. Whats wrong? Thanks
<Border Name="brdClasses" Background="#FF2c3e50">
<Border.RenderTransform>
<ScaleTransform x:Name="MyAnimatedScaleTransform"
ScaleX="1" ScaleY="1" />
</Border.RenderTransform>
<Border.Triggers>
<EventTrigger SourceName="button1" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard Name="MyBeginStoryboard">
<Storyboard >
<DoubleAnimation
Storyboard.TargetName="MyAnimatedScaleTransform"
Storyboard.TargetProperty="(ScaleTransform.ScaleX)"
To="3.0" Duration="0:0:10" AutoReverse="True" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Border.Triggers>
</Border>
I Dont know why your code doent works... But I did a simple example in a specific way.. if it helps make use of that..
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Name="brdClasses" Grid.Row="1" Background="#FF2c3e50" Height="100" Width="150">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
</Border>
<Button Content="Button1" x:Name="button1">
<Button.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button1">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="brdClasses">
<EasingDoubleKeyFrame KeyTime="0" Value="3"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>

Style with image as parameter

I wonder how can i parametrize an image source inside an style, and this style is used inside another style. Let me try to be more clear.
I defined an style for buttons, the style has an image. Then i have another style. On that style, I have two buttons (i´ve applied the button style), and i want to able to change the image of each button. But i can´t get it work.
The first part of the code defines a style for a button the idea is to change the image as needed to represent an action.
This is my code:
<Style x:Key="InnerInscribirseButtonMatch" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ControlTemplate.Resources>
<Storyboard x:Key="MouseOver">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="Blur_back">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="-0.666"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Blur_back">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.705"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="contentPresenter">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="2.665"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="contentPresenter">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="2.999"/>
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="Blur_back">
<EasingColorKeyFrame KeyTime="0" Value="#FFE9E9A7"/>
<EasingColorKeyFrame KeyTime="0:0:0.1" Value="#FFF1F0DD"/>
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="3"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="4"/>
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="Back">
<EasingColorKeyFrame KeyTime="0" Value="#FF356AA0"/>
<EasingColorKeyFrame KeyTime="0:0:0.1" Value="#FF1264B6"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Rectangle x:Name="Blur_back" RadiusY="5" RadiusX="5" Stroke="#FF3F4C6B" StrokeThickness="2" Fill="#FF5B8BBC" Margin="-4.5,-4" Opacity="0" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Effect>
<BlurEffect Radius="7"/>
</Rectangle.Effect>
</Rectangle>
<Rectangle x:Name="Back" RadiusY="5" RadiusX="5" Stroke="#FF3F4C6B" StrokeThickness="2" Fill="#FF356AA0"/>
<Rectangle x:Name="Glass" RadiusY="5" RadiusX="5" Stroke="#FF3F4C6B" StrokeThickness="2" Fill="White" Height="Auto" VerticalAlignment="Stretch" Opacity="0.15" Margin="0,0,0,61" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" RecognizesAccessKey="True" VerticalAlignment="Bottom" RenderTransformOrigin="0.5,0.5" Margin="13.766,0,15.766,14.351" d:LayoutOverrides="Width">
<ContentPresenter.Effect>
<DropShadowEffect Opacity="0.77"/>
</ContentPresenter.Effect>
<ContentPresenter.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
<Image x:Name="image" Margin="12,3.5,17,22.5" RenderTransformOrigin="0.5,0.5" Width="64" Height="64" Source="apuntarlista.png">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Grid>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseDown">
<BeginStoryboard x:Name="MouseOver_BeginStoryboard" Storyboard="{StaticResource MouseOver}"/>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseUp">
<StopStoryboard BeginStoryboardName="MouseOver_BeginStoryboard"/>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<StopStoryboard BeginStoryboardName="MouseOver_BeginStoryboard"/>
</EventTrigger>
<Trigger Property="IsCancel" Value="False"/>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
well, this is the part i want to customize. The source part: Source="apuntarlista.png"
<Image x:Name="image" Margin="12,3.5,17,22.5" RenderTransformOrigin="0.5,0.5" Width="64" Height="64" Source="apuntarlista.png">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
here, you have the second style
<Style x:Key="ButtonStyleCambiable" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Height="130" Width="Auto" Margin="50,0,-315,0">
<Rectangle x:Name="background" Fill="{Binding BackgroundColor, FallbackValue=#FF932424}" RadiusY="15" RadiusX="15" Stroke="{Binding BorderBackgroundColor, FallbackValue=#FF954444}" StrokeThickness="3" Height="130" Width="375" Margin="0" HorizontalAlignment="Left" d:LayoutOverrides="HorizontalAlignment"/>
<Rectangle x:Name="white_glass" Fill="White" RadiusY="15" RadiusX="15" Stroke="{x:Null}" StrokeThickness="3" Opacity="0.07" Height="65" VerticalAlignment="Top" Width="375" Margin="0" HorizontalAlignment="Left" ClipToBounds="True" d:LayoutOverrides="HorizontalAlignment"/>
<TextBlock HorizontalAlignment="Left" Margin="13,13.901,0,0" TextWrapping="Wrap" Width="272" VerticalAlignment="Center" FontSize="48" FontFamily="Cambria" Foreground="White" Text="{Binding Description, FallbackValue=50/100}" FontWeight="Bold">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="3" Opacity="0.35" BlurRadius="13"/>
</TextBlock.Effect></TextBlock>
<TextBlock HorizontalAlignment="Left" Margin="206,14.192,0,0" TextWrapping="Wrap" Width="122" VerticalAlignment="Top" FontSize="24" FontFamily="Cambria" Foreground="White" FontWeight="Bold" Text="En espera: " d:LayoutOverrides="HorizontalAlignment">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="3" Opacity="0.35" BlurRadius="13"/>
</TextBlock.Effect></TextBlock>
<TextBlock HorizontalAlignment="Left" Margin="210,50.123,0,51.739" TextWrapping="Wrap" Width="109" VerticalAlignment="Stretch" FontSize="24" FontFamily="Cambria" Foreground="White" FontWeight="Bold" Text="Libres: " d:LayoutOverrides="HorizontalAlignment, Height">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="3" Opacity="0.35" BlurRadius="13"/>
</TextBlock.Effect></TextBlock>
<TextBlock HorizontalAlignment="Left" Margin="292,51.123,0,50.739" TextWrapping="Wrap" Width="130" VerticalAlignment="Stretch" FontSize="24" FontFamily="Cambria" Foreground="White" FontWeight="Bold" Text="{Binding FreeSits, FallbackValue=10}" d:LayoutOverrides="HorizontalAlignment, Height">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="3" Opacity="0.35" BlurRadius="13"/>
</TextBlock.Effect></TextBlock>
<TextBlock HorizontalAlignment="Left" Margin="329,15.192,0,0" TextWrapping="Wrap" Width="96" VerticalAlignment="Top" FontSize="24" FontFamily="Cambria" Foreground="White" FontWeight="Bold" Text="{Binding PeopleWaiting, FallbackValue=1}" d:LayoutOverrides="HorizontalAlignment">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="3" Opacity="0.35" BlurRadius="13"/>
</TextBlock.Effect></TextBlock>
<Button Content="Inscribir" HorizontalAlignment="Left" Margin="381,2,0,2" Style="{DynamicResource InnerInscribirseButtonMatch}" Width="129" FontFamily="Calibri" FontSize="24" Foreground="White" Height="Auto" VerticalAlignment="Stretch" Opacity="0.85"/>
<Button Content="Info" HorizontalAlignment="Left" Margin="518,2,0,2" Style="{DynamicResource InnerInscribirseButtonMatch}" Width="129" FontFamily="Calibri" FontSize="24" Foreground="White" Height="Auto" VerticalAlignment="Stretch" Opacity="0.85"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
there i have:
<Button Content="Inscribir" HorizontalAlignment="Left" Margin="381,2,0,2" Style="{DynamicResource InnerInscribirseButtonMatch}" Width="129" FontFamily="Calibri" FontSize="24" Foreground="White" Height="Auto" VerticalAlignment="Stretch" Opacity="0.85"/>
<Button Content="Info" HorizontalAlignment="Left" Margin="518,2,0,2" Style="{DynamicResource InnerInscribirseButtonMatch}" Width="129" FontFamily="Calibri" FontSize="24" Foreground="White" Height="Auto" VerticalAlignment="Stretch" Opacity="0.85"/>
as you can see both buttons use Style="{DynamicResource InnerInscribirseButtonMatch}"
but i want each one to have a diferent image.
How can i do that? I Hope to be clear.
Thanks in advance.
I think that you can define Button.DataContext property, for example, by string, and bind the Image.Source property with control DataContext.
<Button DataContext="apuntarlista.png"
Style="{DynamicResource InnerInscribirseButtonMatch}"
/>
<Button DataContext="apuntarlista2.png"
Style="{DynamicResource InnerInscribirseButtonMatch}"
/>
And in your inner style:
<Image x:Name="image"
RenderTransformOrigin="0.5,0.5"
Width="64" Height="64" Source="{Binding}">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
IMHO i would always try to not change the style so that is needs specific input. Thats what the Content is for and the ContentTemplate.
But of course this is difficult sometimes.
We use for these cases an AttachedProperty
So make a new static class name it for example ButtonIconService. give it an Attached Property named Icon
set it on your buttons like
<Button ButtonIconService.Icon="pathToIcon.png"
<Button ButtonIconService.Icon="pathToOtherIcon.png"
and bind it to your Image in your template.
<Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(ButtonInfoService.Icon)}}"
im not sure at the moments if the brackets around ButtonInfoService.Icon are needed?
Hope that helps.

ScaleTransform for Image

I am trying to increase the size of the image by 20. So I am using ScaleTransform as shown below.. but the following code doesn't do any scale Tranform.. Any help would be appreciated...
<Grid>
<Canvas>
<Canvas Height="50" Width="50" Canvas.Top="10" Canvas.Left="100"
Visibility="Visible">
<Image Name="Img" Source="Help.PNG" Canvas.Left="0" Canvas.Top="0">
</Image>
</Canvas>
<Button Canvas.Left="100" Canvas.Top="100" Height="42.5" Name="button3"
Width="100" Visibility="Visible">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard Name="MoveBox">
<DoubleAnimation Storyboard.TargetName="Img"
Storyboard.TargetProperty="(Image.RenderTransform).(ScaleTransform.ScaleX)"
From="1" To="20" BeginTime="0:0:3.75" Duration="0:0:1.25" />
<DoubleAnimation Storyboard.TargetName="Img"
Storyboard.TargetProperty="(Image.RenderTransform).(ScaleTransform.ScaleY)"
From="1" To="20" BeginTime="0:0:3.75" Duration="0:0:1.25" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Canvas>
</Grid>
Have you tried setting a <RenderTransform> on the image? Something like this:
<Image Name="Img" Source="Help.PNG" Canvas.Left="0" Canvas.Top="0">
<Image.RenderTransform>
<ScaleTransform x:Name="scale" ScaleX="1" ScaleY="1"
CenterX="0.5" CenterY="0.5" />
</Image.RenderTransform>
</Image>
This initialises the RenderTransform so that you can refer to it from elsewhere.
I've had to do this with Silverlight.

Resources