在wince中使用C++语言创建Silverlight的VisualState
2010-08-23 05:29:00 来源:WEB开发网state->SetName(L"State1");
StateCollection->Add(state,NULL);
创建一个新的故事板,并将其设置到刚创建的状态中
IXRStoryboardPtr Storyboard;
app->CreateObject(IID_IXRStoryboard,&Storyboard);
state->SetStoryboard(Storyboard);
创建一个IXRDoubleAnimationUsingKeyFrames对象,将它添加到故事板中,
[注:IXRDoubleAnimationUsingKeyFrames派生自IXRTimeline,通过在不同帧时对同一属性设置不同的数值来实现动画效果]
IXRTimelineCollectionPtr children;
Storyboard->GetChildren(&children);
IXRDoubleAnimationUsingKeyFramesPtr animation;
app->CreateObject(IID_IXRDoubleAnimationUsingKeyFrames,&animation);
children->Add(animation,NULL);
设置animation对象的通用属性
XRTimeSpan span;
memset(&span,0,sizeof(XRTimeSpan));
animation->SetBeginTime(&span);
animation->SetBeginTime(&span);
animation->SetDuration(&duration);
animation->SetAttachedProperty(L"Storyboard.TargetName",L"rectangle");
animation->SetAttachedProperty(L"Storyboard.TargetProperty",L"(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)");
创建新的一帧,并将其添加到animation的帧集合中
IXRDoubleKeyFrameCollectionPtr frameCollection;
animation->GetKeyFrames(&frameCollection);
IXRSplineDoubleKeyFramePtr keyFrame;
app->CreateObject(IID_IXRSplineDoubleKeyFrame,&keyFrame);
XRKeyTime time;
time.Ticks = time.TicksPerSecond;
keyFrame->SetKeyTime(&time);
keyFrame->SetValue(75);
frameCollection->Add(keyFrame,NULL);
OK,大功告成,转换状态,看到了矩形的变化过程
Root->GoToVisualState(L"State1",true);
更多精彩
赞助商链接