当前位置: 代码迷 >> Silverlight >> 请教这段动画用C#怎么办
  详细解决方案

请教这段动画用C#怎么办

热度:6230   发布时间:2013-02-26 00:00:00.0
请问这段动画用C#怎么处理?
 功能是在0.5秒之内将字体从粗体变为正常.我用了Blend做出来了,但是用C#不知道应该怎么做。

  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.FontWeight)" Storyboard.TargetName="_3TextBlock">
                <DiscreteObjectKeyFrame KeyTime="0">
                    <DiscreteObjectKeyFrame.Value>
                        <FontWeight>Bold</FontWeight>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
                <DiscreteObjectKeyFrame KeyTime="0:0:0.5">
                    <DiscreteObjectKeyFrame.Value>
                        <FontWeight>Normal</FontWeight>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
            </ObjectAnimationUsingKeyFrames>
------解决方案--------------------------------------------------------

ObjectAnimationUsingKeyFrames animation=new ObjectAnimationUsingKeyFrames();
    DiscreteObjectKeyFrame k1=new DiscreteObjectKeyFrame();
    DiscreteObjectKeyFrame k2=new DiscreteObjectKeyFrame();
    k1.KeyTime=KeyTime.FromPercent(0);
    k1.Value=FontWeights.Bold;
    k2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.Parse("0:0:0.5"));
    k2.Value=FontWeights.Normal;
    animation.KeyFrames.Add(k1);
    animation.KeyFrames.Add(k2);
  this._3TextBlock.BeginAnimation(TextBlock.FontWeightProperty,animation);

------解决方案--------------------------------------------------------
引用:
C# code

ObjectAnimationUsingKeyFrames animation=new ObjectAnimationUsingKeyFrames();
    DiscreteObjectKeyFrame k1=new DiscreteObjectKeyFrame();
    DiscreteObjectKeyFrame k2=new DiscreteObjectKeyF……
非常不错!
------解决方案--------------------------------------------------------
每一个节点都是对象 
可以看看msdn 这些对象 用c# 是如何使用的  
------解决方案--------------------------------------------------------
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(500);
  相关解决方案