问题
I would like to create a Storyboard in my ViewModel like this:
public void OnEventHandler(DrehtellerMoved e)
{
int angle = e.steps * 72;
myStoryboard = new Storyboard();
myStoryboard.Duration = new Duration(TimeSpan.FromMilliseconds(e.speed);
DoubleAnimation myAnimation = new DoubleAnimation()
{
By = angle,
Duration = storyboard.Duration
};
Storyboard.SetTargetProperty(myAnimaiton, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"));
Storyboard.SetTarget(myAnimation, rotateImage);
myStoryboard.Begin();
}
Where myStoryboard
is a public property.
Now I would like to bind myStoryboard
to the Image in XAML for example like this:
<Image x:Name="rotateImage" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Source="{Binding myImage}" Storyboard="{Binding myStoryboard}">
<Image.RenderTransform>
<RotateTransform/>
</Image.RenderTransform>
</Image>
So is it somehow possible to bind the Storyboard, like this or in any other way from the ViewModel, so that I can run the myStoryboard.Begin()
function in the Event Handler? Or does anyone has an idea for a workaround, because I am clueless atm.
来源:https://stackoverflow.com/questions/57409366/is-it-possible-to-bind-a-c-sharp-storyboard-object-on-an-image-in-xaml