Silverlight的界面是通过控件套用控件来改变页面的布局与实现体验者的视觉效果的。本文介绍Silverlight即时显示JavaScript程序的状态,由灵为详细介绍JavaScript实现对Silverlight的控件访问、修改、删除、创建。
下面的实例是JavaScript循环创建动画的效果,显示内容可以随意改变。控件的格式是XAML中定义的TextBlock(文本控件),包括Animation创建,添加,和删除等功能。
function goAnimation(){
if(charIndex<writeText.length)
{
var this_char=writeText.substr(charIndex,1);
if(this_char!=" ")
{
var t_control=_silverlight_c.content.createFromXaml('<TextBlock xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml" Text="Hello" x:Name="t'+charIndex+'"><TextBlock.RenderTransform><TransformGroup><ScaleTransform ScaleX="1" ScaleY="1"/><SkewTransform AngleX="0" AngleY="0"/><RotateTransform Angle="0"/><TranslateTransform X="0" Y="0"/></TransformGroup></TextBlock.RenderTransform></TextBlock>');
CanvasLeft+=split_width;
for(var i in txtFormat){t_control[i]=txtFormat[i];}
t_control["Canvas.Top"]=-20;
t_control["Canvas.Left"]=CanvasLeft;
t_control.foreground="#ffffffff";
t_control.Text=this_char;
_silverlight_c.content.root.children.add(t_control);
var storyboard_str='<Storyboard xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml" x:Name="animation'+charIndex+'">';
storyboard_str+='<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="t'+charIndex+'" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">';
storyboard_str+='<SplineDoubleKeyFrame KeySpline="0.091,0.532,1,1" KeyTime="00:00:00.6000000" Value="-360"/>';
storyboard_str+="</DoubleAnimationUsingKeyFrames>";
storyboard_str+='<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="t'+charIndex+'" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">';
storyboard_str+='<SplineDoubleKeyFrame KeySpline="0.091,0.532,1,1" KeyTime="00:00:00.6000000" Value="'+CanvasTop+'"/>';
storyboard_str+='</DoubleAnimationUsingKeyFrames>';
storyboard_str+='<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="t'+charIndex+'" Storyboard.TargetProperty="(UIElement.Opacity)">';
storyboard_str+='<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.055"/>';
storyboard_str+='<SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>';
storyboard_str+='</DoubleAnimationUsingKeyFrames>';
storyboard_str+="</Storyboard>";
var storyboard_control=_silverlight_c.content.createFromXaml(storyboard_str);
t_control.Resources.add(storyboard_control);
storyboard_control.begin();
}
CanvasLeft+=split_width;
charIndex++;
setTimeout("goAnimation()",100);
}
}