Okay I want to do some animation in WPF to move something in from the right of the screen.
In xaml I do this
<Image x:Name="myImage" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Stretch="Uniform">
<EventTrigger RoutedEvent="Image.Loaded" >
<ThicknessAnimation Name="Move" BeginTime="0:0:0" From="500,0,-500,0" To="0,0,0,0" Duration="0:0:7" Storyboard.TargetProperty="(Margin)" DecelerationRatio="0.9"></ThicknessAnimation>
And it works perfectly. Now that's great but I want to vary some of the parameters and do a reverse sometime later in the code. Was easy enough to trigger this on load.
I thought, okay I will transfer this to a function in the .cs file for this Control. Therefore when the function is called the control will do what it is told.
public void makeanim()
var sb = new Storyboard();
var SlideAnimation = new ThicknessAnimation
Duration = new Duration(TimeSpan.FromSeconds(10)),
From = new Thickness(500, 0, -500, 0),
To = new Thickness(0),
DecelerationRatio = 0.9f
Storyboard.SetTargetProperty(SlideAnimation, new PropertyPath("Margin"));
No matter what I do I cannot figure out how to get this to target the Margin on the control. What I get when the code runs is
System.InvalidOperationException: 'No applicable name scope exists to resolve the name 'mycontrol'.
I've tried various other things, variations of Target Name and TargetProperty but all fail to compile or come up with similar issues on execution. Have been looking for a clear guide (though I did follow the MS one through using my control rather than their rectangle). Nothing seems to work so I suspect I have a fundemental mis-understanding going on here. Can anyone point me in the right direction?