Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It works when you animate the Background/Fill Property directly, using the name of the object (e.g. Rectangle) you want to animate as Storyboard.TargetName:</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;Grid.Resources&gt; &lt;LinearGradientBrush x:Key="Outline" EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#7F7CE3FF" Offset="0"/&gt; &lt;GradientStop Color="#7F047695" Offset="1"/&gt; &lt;GradientStop Color="#FFFFFFFF" Offset="0.942"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Grid.Resources&gt; &lt;Border Name="border" Background="{StaticResource Outline}" Width="200" Height="200" /&gt; &lt;/Grid&gt; &lt;Window.Triggers&gt; &lt;EventTrigger RoutedEvent="Window.Loaded"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Offset)"&gt; &lt;SplineDoubleKeyFrame KeyTime="00:00:0" Value="0"/&gt; &lt;SplineDoubleKeyFrame KeyTime="00:00:1" Value="1"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/Window.Triggers&gt; </code></pre> <p></p> <p><strong>Edit</strong></p> <p>From code behind it seems to be totally possible:</p> <p>XAML:</p> <pre><code>&lt;Grid Name="grid"&gt; &lt;Grid.Resources&gt; &lt;LinearGradientBrush x:Key="Outline" EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#7F7CE3FF" Offset="0"/&gt; &lt;GradientStop Color="#7F047695" Offset="1"/&gt; &lt;GradientStop Color="#FFFFFFFF" Offset="0.942"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Grid.Resources&gt; &lt;Border Background="{StaticResource Outline}" Width="100" Height="100" HorizontalAlignment="Left" /&gt; &lt;Border Background="{StaticResource Outline}" Width="100" Height="100" HorizontalAlignment="Right" /&gt; &lt;/Grid&gt; </code></pre> <p>C# code behind:</p> <pre><code> LinearGradientBrush b = grid.Resources["Outline"] as LinearGradientBrush; b.GradientStops[0].BeginAnimation(GradientStop.OffsetProperty, new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1)))); </code></pre>
 

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