protected override void CopyCurrentValueCore(Animatable sourceAnimatable) { // The timeline to copy properties from. // If this parameter is null, this timeline is constructed with default property values. // if(sourceAnimatable == null) // CopyCore(sourceFreezable); }
public DeploymentAnimation(Dispatcher dispatcher, Animatable animationedObject, bool isDeploying, double animationTime, double stowedValue, double deployedValue) { _Dispatcher = dispatcher; _AnimationedObject = animationedObject; _IsDeploying = isDeploying; _StowedValue = stowedValue; _DeployedValue = deployedValue; AnimationTime = animationTime; _StopAnimation = new DoubleAnimation(); _StopAnimation.BeginTime = null; }
//动画 public static void DoMove(Animatable uie, DependencyProperty dp, double to, double ar, double dr, double duration) { var doubleAnimation = new DoubleAnimation { To = to, Duration = TimeSpan.FromSeconds(duration), AccelerationRatio = ar, DecelerationRatio = dr, FillBehavior = FillBehavior.HoldEnd };//创建双精度动画对象 uie.BeginAnimation(dp, doubleAnimation);//设置动画应用的属性并启动动画 }
internal void Initialize(DependencyObject d, DependencyProperty dp) { Debug.Assert(_dependencyObject == null); Debug.Assert(_dependencyProperty == null); Animatable a = d as Animatable; if (a != null) { _dependencyObject = a.GetWeakReference(); } else { // _dependencyObject = new WeakReference(d); } _dependencyProperty = dp; }
/*private List<Tuple<IAnimatable, DependencyProperty>> animatedPropertyList = new List<Tuple<IAnimatable, DependencyProperty>>();*/ /// <summary> /// アニメーションを開始します。 /// </summary> public void Begin(Animatable target) { foreach (var anim in Children) { if (anim == null) { continue; } var animTarget = GetTarget(anim); if (animTarget == null) { animTarget = target; var targetPath = GetTargetPath(anim); if (!string.IsNullOrEmpty(targetPath)) { var targetProperty = WPFUtil.GetDependencyProperty( target.GetType(), targetPath); if (targetProperty != null) { var t = target.GetValue(targetProperty) as Animatable; if (t != null) { animTarget = t; } } } } var property = WPFUtil.GetDependencyProperty( animTarget.GetType(), GetTargetProperty(anim)); if (property != null) { animTarget.BeginAnimation(property, anim); } /*this.animatedPropertyList.Add( Tuple.Create(animTarget, property));*/ } }
protected override void CopyCurrentValueCore(Animatable sourceAnimatable) {}
/// <summary> /// The animate opacity. /// </summary> /// <param name="obj"> /// The obj. /// </param> /// <param name="toOpacity"> /// The to opacity. /// </param> /// <param name="animationTime"> /// The animation time. /// </param> private void AnimateOpacity(Animatable obj, double toOpacity, double animationTime) { var animation = new DoubleAnimation(toOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5 }; animation.Completed += this.AnimationCompleted; obj.BeginAnimation(UIElement.OpacityProperty, animation); }
static void Animate(Animatable element, DependencyProperty property, double to) { element.BeginAnimation(property, new DoubleAnimation(to, new Duration(animationTime), FillBehavior.HoldEnd), HandoffBehavior.SnapshotAndReplace); }
/// <summary> /// This should be called at the end of any method that alters the /// storage in any way. This method will make sure the peer dp is /// set correctly and notify Animatables if something changes. /// </summary> internal void WritePostscript() { DependencyObject d = (DependencyObject)_dependencyObject.Target; if (d == null) { return; } FrugalMap animatedPropertyMap = AnimatedPropertyMapField.GetValue(d); if (animatedPropertyMap.Count == 0 || animatedPropertyMap[_dependencyProperty.GlobalIndex] == DependencyProperty.UnsetValue) { if (!IsEmpty) { // This is kind of tricky: // // Because FrugalMap is a struct instead of a class, we must // be sure to add this AnimationStorage to the map before // setting the FrugalMap into the UncommonField storage. If // we don't and the FrugalMap is empty then an empty FrugalMap // will be set into the UncommonField storage. If we were to // then add our AnimationStorage to the local FrugalMap, it // would only allocate its own internal storage at that point // which would not apply to the FrugalMap we set into the // UncommonField storage. Once a FrugalMap has allocated its // internal storage, though, that storage is copied with the // FrugalMap. This is what will happen when we add our // AnimationStorage to the FrugalMap first as we do below: animatedPropertyMap[_dependencyProperty.GlobalIndex] = this; // Since FrugalMap is a struct and adding a new value to it // may re-allocate the storage, we need to set this value // each time we make a change to the map. AnimatedPropertyMapField.SetValue(d, animatedPropertyMap); if (animatedPropertyMap.Count == 1) { d.IAnimatable_HasAnimatedProperties = true; } // If this the target is an Animatable we'll need to // invalidate it so that the animation resource for this // newly animated property will be passed across to the UCE. Animatable a = d as Animatable; if (a != null) { a.RegisterForAsyncUpdateResource(); } // If this AnimationStorage is a resource, add it to the // channel now. DUCE.IResource animationResource = this as DUCE.IResource; if (animationResource != null) { DUCE.IResource targetResource = d as DUCE.IResource; if (targetResource != null) { using (CompositionEngineLock.Acquire()) { int channelCount = targetResource.GetChannelCount(); for (int i = 0; i < channelCount; i++) { DUCE.Channel channel = targetResource.GetChannel(i); if (!targetResource.GetHandle(channel).IsNull) { animationResource.AddRefOnChannel(channel); } } } } } } } else { Debug.Assert(animatedPropertyMap.Count > 0); Debug.Assert(animatedPropertyMap[_dependencyProperty.GlobalIndex] != DependencyProperty.UnsetValue); if (IsEmpty) { // If this AnimationStorage is a resource, release it from // the channel now. DUCE.IResource animationResource = this as DUCE.IResource; if (animationResource != null) { DUCE.IResource targetResource = d as DUCE.IResource; if (targetResource != null) { using (CompositionEngineLock.Acquire()) { int channelCount = targetResource.GetChannelCount(); for (int i = 0; i < channelCount; i++) { DUCE.Channel channel = targetResource.GetChannel(i); if (!targetResource.GetHandle(channel).IsNull) { animationResource.ReleaseOnChannel(channel); } } } } } // If this the target is an Animatable we'll need to // invalidate it so that the animation resource for this // no longer animated property will no longer be passed // across to the UCE. Animatable a = d as Animatable; if (a != null) { a.RegisterForAsyncUpdateResource(); } animatedPropertyMap[_dependencyProperty.GlobalIndex] = DependencyProperty.UnsetValue; if (animatedPropertyMap.Count == 0) { AnimatedPropertyMapField.ClearValue(d); d.IAnimatable_HasAnimatedProperties = false; } else { AnimatedPropertyMapField.SetValue(d, animatedPropertyMap); } // We've removed animation storage for this DP, so if we were storing the local // base value here then it has to go back to its non-animated storage spot. if (_baseValue != DependencyProperty.UnsetValue) { d.SetValue(_dependencyProperty, _baseValue); } } } // recompute animated value d.InvalidateProperty(_dependencyProperty); }
/*private void face_MouseLeave(object sender, MouseEventArgs e) { var el = (ModelUIElement3D) sender; var model = el.Model as GeometryModel3D; var mg = model.Material as MaterialGroup; var dm = mg.Children[0] as DiffuseMaterial; AnimateOpacity(dm.Brush, 0.8, 200); } private void face_MouseEnter(object sender, MouseEventArgs e) { var el = (ModelUIElement3D) sender; var model = el.Model as GeometryModel3D; var mg=model.Material as MaterialGroup; var dm=mg.Children[0] as DiffuseMaterial; AnimateOpacity(dm.Brush, 1.0, 200); }*/ private void AnimateOpacity(Animatable obj, double toOpacity, double animationTime) { var a = new DoubleAnimation(toOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5 }; a.Completed += new EventHandler(a_Completed); obj.BeginAnimation(UIElement.OpacityProperty, a); }