新聞中心
Silverlight工具中內(nèi)置了很多種控件。開發(fā)人員使用這些Silverlight控件可以輕松的完成界面圖形的操作,以及一些音頻視頻的相關操作。Silverlight的界面是通過控件套用控件來改變頁面的布局與實現(xiàn)體驗者的視覺效果的。本文介紹Silverlight即時顯示JavaScript程序的狀態(tài),詳細介紹JavaScript實現(xiàn)對Silverlight的控件訪問、修改、刪除、創(chuàng)建。#t#

成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設,南崗企業(yè)網(wǎng)站建設,南崗品牌網(wǎng)站建設,網(wǎng)站定制,南崗網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,南崗網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
提示:對控件進行操作,如果在控件的onLoad之前訪問和操作都會出現(xiàn)異常!,是因為找不到對象。
下面的Silverlight控件實例是JavaScript循環(huán)創(chuàng)建動畫的效果,顯示內(nèi)容可以隨意改變??丶母袷绞荴AML中定義的TextBlock(文本控件),包括Animation創(chuàng)建,添加,和刪除等功能。
變量說明:
- var txtFormat=new _textBlock();
//字體格式對象 - var writeText="Welcom to WPF.COM!";
//運畫顯示內(nèi)容 - var CanvasLeft=0;
//隨環(huán)改變 - var CanvasTop=0;
//加載的XAML中的高度位置 - var charIndex=0;
//顯示的字符索引 - var split_width=15;
//每一個字符的寬度,可以對此智能改變 - var _silverlight_c;
//指定的Silverlight控件對象
在Page.xaml.js文件中創(chuàng)建了_textBlock類,使用此類記錄textBlock中的格式,大小信息。
- function _textBlock()
- {
- this.fontFamily="";
- this.width=0;
- this.height=0;
- this.textWrapping="Wrap";
- this.fontSize=0.0;
- }
- var txtFormat=new _textBlock();
Silverlight控件在onLoad事件中加載了XAML中的格式,并把樣式控件刪除,并且調(diào)用了顯示動畫的方法(goAnimation)。
- handleLoad: function(control,
userContext, rootElement)- {
- this.control = control;
- _silverlight_c=control;
- var tStyle=control.content.
findName("tStyle");- for(var i in txtFormat)
- {
- txtFormat[i]=tStyle[i];
- }
- CanvasLeft=tStyle["Canvas.Left"];
- CanvasTop=tStyle["Canvas.Top"];
- control.content.root.children.
remove(tStyle);- tStyle=null;
- goAnimation();
- }
下面是goAnimation的代碼:
- function goAnimation(){
- if(charIndex
- {
- var this_char=writeText.substr(charIndex,1);
- if(this_char!=" ")
- {
- var t_control=_silverlight_c.content.
createFromXaml('schemas.microsoft.com/winfx/2006/xaml"
Text="Hello" x:Name="t'+charIndex+'">- ');
- 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='
schemas.microsoft.com/winfx/2006/xaml"
x:Name="animation'+charIndex+'">';- storyboard_str+='
BeginTime="00:00:00" Storyboard.TargetName=
"t'+charIndex+'" Storyboard.TargetProperty=
"(UIElement.RenderTransform).(TransformGroup.
Children)[2].(RotateTransform.Angle)">';- storyboard_str+='
KeySpline="0.091,0.532,1,1" KeyTime="00:00:00.
6000000" Value="-360"/>';- storyboard_str+="";
- storyboard_str+='
BeginTime="00:00:00" Storyboard.TargetName=
"t'+charIndex+'" Storyboard.TargetProperty="
(UIElement.RenderTransform).(TransformGroup.
Children)[3].(TranslateTransform.Y)">';- storyboard_str+='
KeySpline="0.091,0.532,1,1" KeyTime="00:00:00.
6000000" Value="'+CanvasTop+'"/>';- storyboard_str+='';
- storyboard_str+='
BeginTime="00:00:00" Storyboard.TargetName=
"t'+charIndex+'" Storyboard.TargetProperty="
(UIElement.Opacity)">';- storyboard_str+='
KeyTime="00:00:00" Value="0.055"/>'; - storyboard_str+='
KeyTime="00:00:00.6000000" Value="1"/>'; - storyboard_str+='';
- storyboard_str+="";
- 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);
- }
- }
使用content.createFromXaml方法創(chuàng)建Silverlight中的對象。
使用content.findName 利用x:Name查找名稱對象
使用silverlight_control.children.add添加控件。
使用silverlight_control.Resources.add添加StoryBoard動畫對象(Storyboard)。
storyboard_obj.Begin播放。
Silverlight控件的具體操作方法就為大家介紹到這里。
新聞標題:Silverlight控件相關操作技巧講解
文章URL:http://fisionsoft.com.cn/article/ccicodg.html


咨詢
建站咨詢
