Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Problem in Pausing a Storyboard in WPF ?

Problem in Pausing a Storyboard in WPF ?

Scheduled Pinned Locked Moved WPF
questioncsharpwpfhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohammad Dayyan
    wrote on last edited by
    #1

    Hi, I'm gonna pause a Storyboard in WPF, so I've used below code :

    Storyboard TheStoryboard;

    //Constructor
    public window
    {
    TheStoryboard = (Storyboard)this.FindResource("TheStoryboardName");
    }

    private void MenuItemPause_Click(object sender, RoutedEventArgs e)
    {
    TheStoryboard.Pause();
    }

    But nothing happen! What is the right way to do that ? Thanks.

    B 1 Reply Last reply
    0
    • M Mohammad Dayyan

      Hi, I'm gonna pause a Storyboard in WPF, so I've used below code :

      Storyboard TheStoryboard;

      //Constructor
      public window
      {
      TheStoryboard = (Storyboard)this.FindResource("TheStoryboardName");
      }

      private void MenuItemPause_Click(object sender, RoutedEventArgs e)
      {
      TheStoryboard.Pause();
      }

      But nothing happen! What is the right way to do that ? Thanks.

      B Offline
      B Offline
      BlitzPackage
      wrote on last edited by
      #2

      I think you should get a reference to the actual storyboard that's running. What you may be getting a reference to with the code above is that storyboard class, but not the instantiation that's actually running. In addition, I would suggest using the keyword "as" to perform the cast. Then check to see if the variable is null. The cast you currently use, if it does not work, will throw an exception. The keyword "as" simply returns null if the cast does not work. Also, look into "TryFindResource" as opposed to "FindResource". I believe it works the same way in that it will return null if the resource is not found. Again, check for null before using it. Both of these suggested changes will make your code, in general, more robust. Let me know if this helps. Blitz

      M 1 Reply Last reply
      0
      • B BlitzPackage

        I think you should get a reference to the actual storyboard that's running. What you may be getting a reference to with the code above is that storyboard class, but not the instantiation that's actually running. In addition, I would suggest using the keyword "as" to perform the cast. Then check to see if the variable is null. The cast you currently use, if it does not work, will throw an exception. The keyword "as" simply returns null if the cast does not work. Also, look into "TryFindResource" as opposed to "FindResource". I believe it works the same way in that it will return null if the resource is not found. Again, check for null before using it. Both of these suggested changes will make your code, in general, more robust. Let me know if this helps. Blitz

        M Offline
        M Offline
        Mohammad Dayyan
        wrote on last edited by
        #3

        Thanks, At last I could resolve the problem. I've written it here[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups