Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6950665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:07:14+00:00 2026-05-27T14:07:14+00:00

why does it not work the way it should? There is no movement…. below

  • 0

why does it not work the way it should? There is no movement…. below is the code:

namespace MovingBox
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Storyboard myStoryboard = new Storyboard();

        public MainWindow()
        {
            InitializeComponent();

        }

        private void Start_Animation(object sender, EventArgs e)
        {
            myStoryboard.Begin();
        }

        private void MyAnimatedRectangle_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Start_Animation(sender, e); 
        }
    }
}

XAML:

<Window x:Class="MovingBox.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">



<Grid>
    <StackPanel>
        <StackPanel.Resources>
            <Storyboard x:Name="myStoryboard" x:Key="myStoryboardKey">
                <DoubleAnimation
      Storyboard.TargetName="MyAnimatedRectangle"
      Storyboard.TargetProperty="Opacity"
      From="1.0" To="0.0" Duration="0:0:5" 
      AutoReverse="True" RepeatBehavior="Forever" />
            </Storyboard>
        </StackPanel.Resources>

        <Rectangle Loaded="Start_Animation" x:Name="MyAnimatedRectangle"
 Width="100" Height="100" Fill="Blue" MouseDown="MyAnimatedRectangle_MouseDown" />

    </StackPanel>
</Grid>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:07:14+00:00Added an answer on May 27, 2026 at 2:07 pm

    The myStoryBoard you are referring to in the Start_Animation method is a different one from the one in the XAML.

    Here’s a working version that searches for the storyboard resource:
    Note that I removed the Storyboard myStoryboard = new Storyboard();

    private void MyAnimatedRectangle_MouseDown(object sender, MouseButtonEventArgs e)
    {
        PlayMyStoryboard(sender as FrameworkElement);
    }
    
    private void PlayMyStoryboard(FrameworkElement sender)
    {
        var sb = sender.FindResource("myStoryboardKey") as Storyboard;
        if (sb != null)
        {
            sb.Begin();
        }
    }
    
    private void Start_Animation(object sender, RoutedEventArgs e)
    {
        PlayMyStoryboard(sender as FrameworkElement);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Two way binding does not work on my custom control with the following internals:
DataAnnotations does not work with buddy class. The following code always validate true. Why
The XAML below does not work (the text does not change when mousing over):
This javascript code does not work in IE8, but works in Firefox and Google
Following code does NOT work, but it expresses well what I wish to do.
py2exe does not work with the standard email module Hello. I am trying to
IIS does not work when I start applications like Skype since it also uses
This does NOT work: Sub X() Dim A As Access.Application Set A = CreateObject(Access.Application)
The following method does not work because the inner block declares a variable of
I know that XSLT does not work in procedural terms, but unfortunately I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.