[Unity] Dynamically changing Animation Values with Bindings
Posted: 08 Oct 2014, 01:14
Hey all, hopefully this is something simple that I have just overlooked. I'm trying to animate the ViewBox property of an ImageBrush through an animation. The catch is that I need to specify the value to animate to at runtime so I figured this would be a perfect time to take a stab at adding properties to the user control and use bindings for this.
Below is the code I current have set up and I am calling AnimateToView with a new Rect(50, 20, 348, 236) so the image being displayed should zoom in. However, nothing happens. when I update the animation storyboard to just use a hard coded value of To="50, 20, 348, 236" it works as expected. So I'm not sure what it is that I am missing. Any thoughts?
Below is the code I current have set up and I am calling AnimateToView with a new Rect(50, 20, 348, 236) so the image being displayed should zoom in. However, nothing happens. when I update the animation storyboard to just use a hard coded value of To="50, 20, 348, 236" it works as expected. So I'm not sure what it is that I am missing. Any thoughts?
Code: Select all
<UserControl
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:noesis="clr-namespace:NoesisGUIExtensions" xmlns:five="clr-namespace:FiveGui"
mc:Ignorable="d" x:Class="FiveGui.UIImageViewer" x:Name="_UIImageViewerControl" d:DesignWidth="1920" d:DesignHeight="1080">
<UserControl.Resources>
<ResourceDictionary>
<Storyboard x:Key="NextFrame">
<RectAnimation To="{Binding Frame}" Duration="0:0:1" Storyboard.TargetName="_Image" Storyboard.TargetProperty="Viewbox"/>
</Storyboard>
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<Rectangle>
<Rectangle.Fill>
<ImageBrush x:Name="_Image" ImageSource="../GUIResources/DefaultImage.png" Viewbox="0,0,448,276" ViewboxUnits="Absolute"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</UserControl>Code: Select all
using Noesis;
namespace FiveGui
{
[Noesis.Extended]
[Noesis.UserControlSource("Assets/GUI/GUIControls/UIImageViewer.xaml")]
public class UIImageViewer : Noesis.UserControl
{
public static DependencyProperty FrameProperty = DependencyProperty.Register("Frame", typeof(Rect), typeof(UIImageViewer), new PropertyMetadata(null));
public Rect Frame
{
get { return GetValue<Rect>(FrameProperty); }
set { SetValue<Rect>(FrameProperty, value); }
}
private Storyboard _nextFrame;
public void OnPostInit()
{
_nextFrame = FindStringResource<Storyboard>("NextFrame");
Frame = new Rect(0, 0, 448, 276);
}
private void AnimateToView(Rect rect)
{
Frame = rect;
_nextFrame.Begin(this);
}
}
}