Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>FINALLY I FOUND THE SOLUTION!!!!! </p> <p>If you recall the error that I got when placing the storyboard in the app.xaml file was:</p> <p>Cannot set a property on object 'System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames' because it is in a read-only state.</p> <p>in other words I could not modify the target property of the storyboard I could just red it. so the solution was to change the <code>Storyboard.TargetName="grid"</code> for <code>Storyboard.TargetName="{binding}"</code></p> <hr> <p>Let me put everything together:</p> <pre><code>step 1: // create your custom storyboard with expression blend or xaml: // let's say it comes out as: &lt;Storyboard x:Key="Storyboard1"&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="grid"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="90"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="103"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="grid"&gt; &lt;EasingPointKeyFrame KeyTime="0:0:1" Value="0.75,0.5"/&gt; &lt;/PointAnimationUsingKeyFrames&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="grid"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="75"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; </code></pre> <p>--</p> <pre><code>step 2: // copy and paste your storyboard to your app.xaml file or to a // resource dictionary (if you paste it in a resource dictionary do not // forget to merge the dictionaries so that your code is able to find the // storyboard as a resource) &lt;Application x:Class="FilesPro2._1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"&gt; &lt;Application.Resources&gt; &lt;Storyboard x:Key="Storyboard1"&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="{Binding}"&gt; &lt;EasingDoubleK .... ..... ... etc </code></pre> <p>--</p> <pre><code>step 3 </code></pre> <p>// replace the Storyboard.TargetName="grid" for Storyboard.TargetName="{Binding}". // Your storyboard resource should no look like:</p> <pre><code>&lt;Application.Resources&gt; &lt;Storyboard x:Key="Storyboard1"&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="{Binding}"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="90"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="{Binding}"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="103"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="{Binding}"&gt; &lt;EasingPointKeyFrame KeyTime="0:0:1" Value="0.75,0.5"/&gt; &lt;/PointAnimationUsingKeyFrames&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="{Binding}"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="75"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; </code></pre> <p>--</p> <pre><code>step 4 //create a method to make it easy to run the same animation on multiple objects: void runStoryboard(string storyboardName, string objectName) { Storyboard sb = FindResource(storyboardName) as Storyboard; foreach (var child in sb.Children) Storyboard.SetTargetName(child, objectName); sb.Begin(this); // do not forget the this keyword } </code></pre> <p>--</p> <pre><code>step 5 // start your animation with the object you wish to animate runStoryboard("Storyboard1", brdBorder.Name); </code></pre> <p>NOTE IMPORTANT:</p> <p>by aware that when creating your storyboard with expression blend, sometimes expression blend will create a render transform group to the control you are animating. in this example I where animating a boarder. and for that boarder to be animated it needed to have </p> <pre><code> &lt;Border.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform/&gt; &lt;SkewTransform/&gt; &lt;RotateTransform/&gt; &lt;TranslateTransform/&gt; &lt;/TransformGroup&gt; &lt;/Border.RenderTransform&gt; </code></pre> <p>In other words, if your animation deals with scaletransform skewtransform etc.. then place that render transform group to all the objects that you plan on animating.</p> <hr> <p>finaly I am able to animate:</p> <pre><code>&lt;Border Name="brdBorder" BorderBrush="Silver" BorderThickness="1" Margin="338,6,0,0" Background="#FFE52E2E" HorizontalAlignment="Left" Width="94" Height="38" VerticalAlignment="Top"&gt; &lt;Border.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform/&gt; &lt;SkewTransform/&gt; &lt;RotateTransform/&gt; &lt;TranslateTransform/&gt; &lt;/TransformGroup&gt; &lt;/Border.RenderTransform&gt; &lt;/Border&gt; // AND &lt;Button Name="mybutton" Content="Test" Height="20" Click="mybutton_Click"&gt; &lt;Button.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform/&gt; &lt;SkewTransform/&gt; &lt;RotateTransform/&gt; &lt;TranslateTransform/&gt; &lt;/TransformGroup&gt; &lt;/Button.RenderTransform&gt; &lt;/Button&gt; AS: runStoryboard("Storyboard1", brdBorder.Name); runStoryboard("Storyboard1", mybutton.Name); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload