当前位置: 首页>>代码示例>>C#>>正文


C# VisualState.SetValue方法代码示例

本文整理汇总了C#中System.Windows.VisualState.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# VisualState.SetValue方法的具体用法?C# VisualState.SetValue怎么用?C# VisualState.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.VisualState的用法示例。


在下文中一共展示了VisualState.SetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddStateAtRuntime

		public void AddStateAtRuntime ()
		{
			Rectangle rect = new Rectangle { Name = RootName };
			VSMControl c = new VSMControl ();
			c.ApplyTemplate ();

			// Create a visual state in code which we will try to use to animate the template element called 'Grid'
			foreach (VisualStateGroup g in VisualStateManager.GetVisualStateGroups (c.TemplateGrid)) {
				VisualState s = new VisualState ();
				s.SetValue (FrameworkElement.NameProperty, "C");
				s.Storyboard = CreateWidthStoryboard (RootName, 600, 700);
				g.States.Add (s);
			}

			// The template element "Grid" can't be found by the new storyboard
			CreateAsyncTest (c,
				() => {
					Assert.IsTrue (VisualStateManager.GoToState (c, "A", false), "#1");
					Assert.Throws<InvalidOperationException> (() => VisualStateManager.GoToState (c, "C", false), "#2");

					// Adding a new element called 'Grid' to the TestPanel does not work
					TestPanel.Children.Add (rect);
					Assert.Throws<InvalidOperationException> (() => VisualStateManager.GoToState (c, "C", false), "#3");

					// The new element is not findable from the control
					Assert.IsNull (c.FindName (RootName), "#4");
					Assert.AreSame (rect, TestPanel.FindName (RootName), "#5");

					// Adding it to the template grid instead
					TestPanel.Children.Remove (rect);
					c.TemplateGrid.Children.Add (rect);

					// It's not findable from the panel, but it is from the Control
					Assert.AreSame (rect, c.FindName (RootName), "#6");
					Assert.IsNull (TestPanel.FindName (RootName), "#7");

					// Once it's findable from the control, the storyboard will resolve to the new element and succeed
					Assert.IsTrue (VisualStateManager.GoToState (c, "C", false), "#8");
			},
			() => {
					Assert.AreEqual (700, rect.Width, "#9");
					// The template element 'Grid' is not changed
					Assert.IsTrue (Double.IsNaN (c.TemplateGrid.Width), "#10");
				}
			);
		}
开发者ID:kangaroo,项目名称:moon,代码行数:46,代码来源:VisualStateManagerTest.cs

示例2: AddNotificationStatesGroup

        /// <summary>
        /// Adds the notification states group.
        /// </summary>
        /// <param name="popupView">The popup view.</param>
        /// <param name="panel">The panel.</param>
        private void AddNotificationStatesGroup(PopupView popupView, Panel panel)
        {
            var uniqueId = Guid.NewGuid();
            var groups = (IList<VisualStateGroup>)VisualStateManager.GetVisualStateGroups(_panel);

            var vsGroup = new VisualStateGroup();
            groups.Add(vsGroup);
            vsGroup.SetValue(FrameworkElement.NameProperty, string.Format(CultureInfo.InvariantCulture, "NotificationState{0}", uniqueId));

            var hideState = new VisualState();
            var showState = new VisualState();
            var showCenterState = new VisualState();
            var showBusyState = new VisualState();

            var showStoryboard = new Storyboard();
            if (_position == PopupPosition.Top)
                PopupHelper.AddFlipFromTopAnimation(showStoryboard, popupView);
            else
                PopupHelper.AddSlideFromLeftAnimation(showStoryboard, popupView);

            showStoryboard.Completed += (o, args) =>
                {
                    if (_duration == 0)
                        return;
                    _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(_duration) };
                    _timer.Start();
                    _timer.Tick += (sender, eventArgs) =>
                        {
                            if (!_isMouseOver)
                                HideNotificationPopup(_timer);
                            else
                                _timeToClose = true;
                        };
                };

            showState.Storyboard = showStoryboard;

            var hideStoryboard = new Storyboard();
            switch (_position)
            {
                case PopupPosition.Right:
                    hideStoryboard.Children.Add(PopupHelper.GetSlideToRightAnimation(popupView));
                    break;
                case PopupPosition.Top:
                    PopupHelper.AddFlipToTopAnimation(hideStoryboard, popupView);
                    break;
                default:
                    hideStoryboard.Children.Add(PopupHelper.GetOpacityZeroAnimation(popupView));
                    break;
            }

            _removeControlsAction = () =>
            {
                panel.Children.Remove(popupView);
                groups.Remove(vsGroup);
                if (_modalBorder != null)
                    _parentPanel.Children.Remove(_modalBorder);
            };

            hideStoryboard.Completed += (o, args) => RemoveControls();

            hideState.Storyboard = hideStoryboard;

            var showCenterStoryboard = new Storyboard();

            showCenterState.Storyboard = showCenterStoryboard;

            var showBusyStoryboard = new Storyboard();
            showBusyState.Storyboard = showBusyStoryboard;

            _showName = string.Format(CultureInfo.InvariantCulture, "Show{0}", uniqueId);
            _hideName = string.Format(CultureInfo.InvariantCulture, "Hide{0}", uniqueId);
            _showCenterName = string.Format(CultureInfo.InvariantCulture, "ShowCenter{0}", uniqueId);
            _showBusyName = string.Format(CultureInfo.InvariantCulture, "ShowBusy{0}", uniqueId);

            showState.SetValue(FrameworkElement.NameProperty, _showName);
            hideState.SetValue(FrameworkElement.NameProperty, _hideName);
            showCenterState.SetValue(FrameworkElement.NameProperty, _showCenterName);
            showBusyState.SetValue(FrameworkElement.NameProperty, _showBusyName);

            vsGroup.States.Add(showState);
            vsGroup.States.Add(showCenterState);
            vsGroup.States.Add(hideState);
            vsGroup.States.Add(showBusyState);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:90,代码来源:PopupBuilder.cs

示例3: ManagedVisualStates

		public void ManagedVisualStates ()
		{
			Rectangle r = new Rectangle { Name = "rect", Width = 0 };
			VisualStateGroup group = new VisualStateGroup ();
			group.SetValue (FrameworkElement.NameProperty, "group");

			VisualState vstate = new VisualState ();
			vstate.SetValue (FrameworkElement.NameProperty, "state");

			DoubleAnimation anim = new DoubleAnimation { From = 100, To = 200, Duration = TimeSpan.FromSeconds (1) };
			anim.SetValue (Control.NameProperty, "ANIMATION");
			Storyboard.SetTargetName (anim, "rect");
			Storyboard.SetTargetProperty (anim, new PropertyPath ("Width"));

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

			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 ((Control) TestPage, "state", false), "#2"));
			Enqueue (() => Assert.IsGreater (99, r.Width, "#3"));
			Enqueue (() => TestPanel.Children.Clear ());
			Enqueue (() => VisualStateManager.GetVisualStateGroups (TestPage).Clear ());
			EnqueueTestComplete();
		}
开发者ID:kangaroo,项目名称:moon,代码行数:28,代码来源:VisualStateManagerTest.cs

示例4: ManagedVisualStates2

		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();
		}
开发者ID:kangaroo,项目名称:moon,代码行数:43,代码来源:VisualStateManagerTest.cs


注:本文中的System.Windows.VisualState.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。