Is it possible to bind a C# Storyboard Object on an Image in xaml?

这一生的挚爱 提交于 2019-12-14 04:02:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!