EDIT 1 : In order to satisfy "Complete, Minimal And Verifiable" Example Requirement
TL:DR; Storyboard doesn't animate at all. Why?
I am attempting to create a storyboard which will animate the offsets of all the gradient stops within a gradient, shifting them from the left to the right.
I'm certain this is just a stupid syntax or argument error or something someplace on my part but I can't find it.
This is the XAML :
<Window
x:Class="GradientShifting.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:GradientShiftDerping"
mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"
AllowsTransparency="True" WindowStyle="None">
<Window.Background>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
</Window>
This is the code behind :
using System;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace GradientShifting {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private Storyboard _sbGradientShifter = new Storyboard( );
public MainWindow( ) {
InitializeComponent( );
this.Loaded += new RoutedEventHandler(
( S, E ) => this.SetupGradientShift( ) );
}
private void SetupGradientShift( ){
GradientBrush BackBrush = this.Background as GradientBrush;
if ( BackBrush != null ) {
/* Ordering by offset is important because
the last color in the gradient requires
special consideration. */
DoubleAnimationUsingKeyFrames DAUKF;
GradientStopCollection GSC = new GradientStopCollection(
BackBrush.GradientStops.OrderBy( GS => GS.Offset ) );
foreach( GradientStop GS in GSC ){
DAUKF = new DoubleAnimationUsingKeyFrames( ) {
KeyFrames = new DoubleKeyFrameCollection( ){
new LinearDoubleKeyFrame(
1.0D, KeyTime.FromPercent( 1.0D )
}, Duration = TimeSpan.FromSeconds( 3 )
};
//Something I am doing from here...
this._sbGradientShifter.Children.Add( DAUKF );
Storyboard.SetTarget( DAUKF, GS );
Storyboard.SetTargetProperty(
DAUKF, new PropertyPath( GradientStop.OffsetProperty ) );
}
this._sbGradientShifter.Begin( this ); //THIS DOES NOTHING.
}
}
So, again - this code doesn't work. I have been able to start the the animation included within the storyboard by calling GradientStop.BeginAnimation
, however Storyboard.Begin
does not work.