Search code examples
c#xamlbackgroundblend

Visual Blend Annimating Image Background


Image from https://www.flickr.com/photos/markusspiske/14201997467/in/album-72157645103340985/ free for commercial use

If the user starts the app there should be a annimated background. The Background of the Maingrid is that picture above. The background should be moved. How can I do this in Visual Blend? I'm aware of how to create annimations in blend but I don't know how to do this kind of annimation.


Solution

  • I believe you are looking for something along the lines of this:

    <Canvas.Resources>
      <Storyboard x:Name="myStoryboard">
    
        <!-- The PointAnimation has a name so it can be accessed
             from code. The To property is left out of the XAML
             because the value of To is determined in code. -->
        <PointAnimation
          x:Name="clockAnimation"
          Storyboard.TargetProperty="Center"
          Storyboard.TargetName="clockImage"
          Duration="0:0:20"/>
      </Storyboard>
    </Canvas.Resources>
    

    And this C# which can be done on a timer or on initialisation:

    double newX = 'Where you want the new X coordinate of the clock';
    double newY = 'Where you want the new Y coordinate of the clock';
    Point myPoint = new Point();
    myPoint.X = newX;
    myPoint.Y = newY;
    clockAnimation.To = myPoint;
    myStoryboard.Begin();
    

    I hope this works for you!