Example #1
0
        private void stackPanel_Loaded(object sender, RoutedEventArgs e)
        {
            var storyboard = new Storyboard();
            var animation = new DoubleAnimation
            {
                From = 900,
                To = 0,
                Duration = new Duration(TimeSpan.FromMilliseconds(500))
            };

            var translatTransform = new TranslateTransform
            {
                Y = 900
            };

            var panel = (StackPanel)sender;
            panel.RenderTransform = translatTransform;

            Storyboard.SetTarget(animation, translatTransform);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Y"));
            storyboard.Children.Add(animation);
            storyboard.Begin();
            
            while (storyboard.GetCurrentState() == ClockState.Active)
            {
            }
            
            this.Storyboard2.Begin();
        }
Example #2
0
        private void Navigate(Directory newDirectory, Storyboard outAnimation, Storyboard inAnimation)
        {
            outAnimation.Begin();

            _curr = newDirectory;
            Action BeginInAnimation = () =>
            {
                inAnimation.Begin();
            };
            Action WorkToDo = () =>
            {
                UpdateItems(BeginInAnimation);
            };
            outAnimation.Completed += new EventHandler((object sender, EventArgs e) =>
            {
                UpdateView(BeginInAnimation);
            });
            Action<object, RunWorkerCompletedEventArgs> RunWorkerCompletedEvent = (object sender, RunWorkerCompletedEventArgs e) =>
            {
                if (outAnimation.GetCurrentState() != ClockState.Active)
                {
                    UpdateView(BeginInAnimation);
                    outAnimation.Stop();
                }
            };

            CreateNewBackgroundWorker(WorkToDo, RunWorkerCompletedEvent)
                .RunWorkerAsync();
        }
Example #3
0
		public void BeginNameNotAttached2 ()
		{
			Storyboard sb = new Storyboard ();
			Storyboard.SetTargetName (sb, "TARGET");
			sb.Begin ();
			Assert.AreEqual (ClockState.Stopped, sb.GetCurrentState ());
			Enqueue (() => sb.Stop ());
			EnqueueTestComplete ();
		}
Example #4
0
		public void BeginNoNameOrTarget ()
		{
			Storyboard sb = new Storyboard ();
			sb.Begin ();
			Assert.AreEqual (ClockState.Stopped, sb.GetCurrentState ());
			Enqueue (() => sb.Stop ());
			EnqueueTestComplete ();
		}
Example #5
0
		public void AddRunningStoryboard ()
		{
			Canvas c = CreateStoryboard ();
			Storyboard sb = (Storyboard) c.Resources ["Storyboard"];

			Storyboard child = new Storyboard { };
			DoubleAnimation animation = new DoubleAnimation { Duration = new Duration (TimeSpan.FromSeconds (1)), From = 10, To = 100 };
			Storyboard.SetTargetName (animation, "A");
			Storyboard.SetTargetProperty (animation, new PropertyPath ("Width"));
			child.Children.Add (animation);

			TestPanel.Children.Add (c);

			Enqueue (delegate {
				// The TargetName isn't resolvable
				Assert.Throws<InvalidOperationException>(() => child.Begin (), "TargetName should not be resolvable");
				Storyboard.SetTargetName (animation, null);
				Assert.Throws<InvalidOperationException> (() => child.Begin (), "Target is not specified");
				Storyboard.SetTarget (child, c.Children [0]);
				child.Begin ();
			});

			Enqueue (delegate {
				Assert.AreEqual (ClockState.Active, child.GetCurrentState (), "Active");
				sb.Children.Add (child);
			});

			Enqueue (delegate {
				Assert.AreEqual (ClockState.Active, child.GetCurrentState (), "#1");
				Assert.AreEqual (ClockState.Stopped, sb.GetCurrentState (), "#2");
			});

			Enqueue (() => { TestPanel.Children.Clear (); TestPanel.Resources.Clear (); });
			EnqueueTestComplete ();
		}
Example #6
0
		public void CompletedEvent ()
		{
			List<ManualResetEvent> handles = new List<ManualResetEvent> ();
			Canvas c = new Canvas ();

			Storyboard sb = new Storyboard { Duration = new Duration (TimeSpan.FromMilliseconds (500)) };
			ManualResetEvent handle = new ManualResetEvent (false);
			handles.Add (handle);
			bool fillingWhenComplete = false;
			bool childrenNotSignalled = true;
			sb.Completed += delegate {
				fillingWhenComplete = ClockState.Filling == sb.GetCurrentState ();
				//Assert.AreEqual (sb.Duration.TimeSpan, sb.GetCurrentTime (), "#1");
				for (int i = 1; i < handles.Count; i++)
					if (handles [i].WaitOne (0))
						childrenNotSignalled = false;
				handle.Set ();
			};
			c.Resources.Add ("Storyboard", sb);

			for (int i = 0; i < 2; i++) {
				DoubleAnimation anim = new DoubleAnimation { From = 10, To = 50 };
				Storyboard child = new Storyboard { Duration = new Duration (TimeSpan.FromMilliseconds (500)) };

				ManualResetEvent h = new ManualResetEvent (false);
				handles.Add (h);
				child.Completed += delegate {
					int count = i;
					h.Set ();
					Assert.AreEqual (ClockState.Filling, child.GetCurrentState (), "#4." + count);
				};

				child.Children.Add (anim);
				sb.Children.Add (child);
				Rectangle r = new Rectangle ();
				Storyboard.SetTarget (child, r);
				Storyboard.SetTargetProperty (child, new PropertyPath ("Width"));
				c.Children.Add (r);
			}

			TestPanel.Children.Add (c);

			Enqueue (() => handles.ForEach (h => h.Reset ()));
			Enqueue (() => sb.Begin ());
			Enqueue (() => {
				Assert.AreEqual ( ClockState.Active, sb.GetCurrentState (), "#1");
			});
			EnqueueConditional (() => handle.WaitOne (0));
			Enqueue (() => Assert.IsTrue (fillingWhenComplete, "Filling when complete"));
			Enqueue (() => Assert.IsTrue (childrenNotSignalled, "Children not signalled"));
			Enqueue (() => {
				for (int i = 0; i < handles.Count; i++)
					Assert.IsTrue (handles [i].WaitOne (10), "#2");
			});
			Enqueue (() => Assert.AreEqual (ClockState.Filling, sb.GetCurrentState (), "Still filling"));

			Enqueue (() => { TestPanel.Children.Clear (); TestPanel.Resources.Clear (); });
			EnqueueTestComplete ();
		}
Example #7
0
		public void ManagedVisualStates2 ()
		{
			Rectangle r = new Rectangle { Width = 0 };
			VisualStateGroup group = new VisualStateGroup ();
			group.SetValue (FrameworkElement.NameProperty, "group2");

			// Create the first visual state
			VisualState vstate = new VisualState ();
			vstate.SetValue (FrameworkElement.NameProperty, "state2");

			DoubleAnimation anim = new DoubleAnimation { From = 100, To = 200, Duration = TimeSpan.FromSeconds (1) };
			Storyboard.SetTarget (anim, r);
			Storyboard.SetTargetProperty (anim, new PropertyPath ("Width"));

			Storyboard sb = new Storyboard ();
			sb.Children.Add (anim);
			vstate.Storyboard = sb;
			group.States.Add (vstate);

			// Create the second visual state
			VisualState vstate2 = new VisualState ();
			vstate2.SetValue (FrameworkElement.NameProperty, "state3");

			Storyboard sb2 = new Storyboard ();
			Storyboard.SetTarget (sb2, r);
			Storyboard.SetTargetProperty (sb2, new PropertyPath ("Width"));

			vstate2.Storyboard = sb2;
			group.States.Add (vstate2);

			// Ensure that the values reset correct
			Enqueue (() => TestPanel.Children.Add (r));
			Enqueue (() => VisualStateManager.GetVisualStateGroups ((FrameworkElement)TestPanel.Parent).Add (group));
			Enqueue (() => Assert.AreEqual(0, r.Width, "#1"));
			Enqueue (() => Assert.IsTrue (VisualStateManager.GoToState (TestPage, "state2", false), "#2"));
			Enqueue (() => Assert.IsGreater (99, r.Width, "#3"));
			Enqueue (() => Assert.IsTrue (VisualStateManager.GoToState (TestPage, "state3", false), "#3"));
			Enqueue (() => Assert.AreEqual (0, r.Width, "#4"));
			Enqueue (() => Assert.AreEqual (ClockState.Filling, sb2.GetCurrentState (), "#5"));
			Enqueue (() => TestPanel.Children.Clear ());
			Enqueue (() => VisualStateManager.GetVisualStateGroups (TestPage).Clear ());
			EnqueueTestComplete();
		}