function onLoad(root, sender, args)
{
var scale = root.findName("scale");
scale.scaleX = 5;
scale.scaleY = 5;
}
MouseLeftButtonDown="mouseDown"
function mouseDown(sender, args)
{
sender.findName("spin").begin();
}
var downloader = plugIn.createObject("downloader");
downloader.addEventListener("downloadProgressChanged", "downloadChanged");
downloader.addEventListener("completed", "downloadCompleted");
function downloadChanged(sender, args)
{
var done = Math.floor(sender.downloadProgress * 100);
var progress = sender.findName("loadingText");
progress.text = "Loading... " + done + "%";
}
function downloadCompleted(sender, args)
{
}
downloader.open("GET", "files.zip");
downloader.send();
if (sender.status != 200)
{
alert("download failed");
return;
}
sender.findName("loadingText").opacity = 0;
var theXaml = sender.getResponseText("body.xaml");
var theContent = sender.getHost().content.createFromXaml(theXaml);
// Add to the Root
var root = sender.findName("root");
root.children.insert(0, theContent);
var theImage = theContent.findName("dynPicture");
theImage.setSource(sender, "bunny.jpg");
var theText = sender.findName("dynText");
theText.setFontSource(sender);
theText.fontFamily = "SmackAttack BB";
DownloadProgressChanged="downloadProgressChanged"
function downloadProgressChanged(sender, args)
{
var width = Math.floor(sender.downloadProgress * 448);
sender.findName("downloadRect").width = width;
}
var isMediaOpened = false;
function timerComplete(sender, args)
{
var player = sender.findName("mPlayer");
if (isMediaOpened)
{
var percent = player.position.seconds /
player.naturalDuration.seconds;
var width = Math.floor(percent * 448);
sender.findName("playingRect").width = width;
}
sender.begin();
}
MediaOpened="mediaOpened"
MediaEnded="mediaEnded"
function mediaOpened(sender, args)
{
isMediaOpened = true;
sender.findName("mPlayer").opacity = 1;
}
function mediaEnded(sender, args)
{
var player = sender.findName("mPlayer");
player.stop();
player.play();
}
var now = new Date();
var secondAnimation = plugIn.content.findName("secondAnimation");
if (secondAnimation)
{
var seconds = now.getSeconds();
var angle = (seconds / 60) * 360;
angle += 180;
secondAnimation.from = angle.toString();
secondAnimation.to = (angle + 360).toString();
}
var now = new Date();
var hourAnimation = plugIn.content.findName("hourAnimation");
var minuteAnimation = plugIn.content.findName("minuteAnimation");
var secondAnimation = plugIn.content.findName("secondAnimation");
if (hourAnimation) {
var hours = now.getHours();
var angle = (hours / 12) * 360 + now.getMinutes()/2;
angle += 180;
hourAnimation.from = angle.toString();
hourAnimation.to = (angle + 360).toString();
}
if (minuteAnimation) {
var minutes = now.getMinutes();
var angle = (minutes / 60) * 360;
angle += 180;
minuteAnimation.from = angle.toString();
minuteAnimation.to = (angle + 360).toString();
}
if (secondAnimation) {
var seconds = now.getSeconds();
var angle = (seconds / 60) * 360;
angle += 180;
secondAnimation.from = angle.toString();
secondAnimation.to = (angle + 360).toString();
}
public void RectangleClick(object sender, MouseEventArgs e)
{
Rectangle r = sender as Rectangle;
Color c = new Color();
c.G = 0;
c.R = 0;
c.B = 0;
c.A = 155;
SolidColorBrush s = new SolidColorBrush(c);
r.Fill = s;
}
public void TextBlockClick(object sender, MouseEventArgs e)
{
TextBlock t = sender as TextBlock;
t.Text += "... again and";
}
Canvas c = o as Canvas;
DoubleAnimation hourAnim = (DoubleAnimation)c.FindName("HourAnimation");
DoubleAnimation minAnim = (DoubleAnimation)c.FindName("MinuteAnimation");
DoubleAnimation secAnim = (DoubleAnimation)c.FindName("SecondAnimation");
DateTime date = DateTime.Now;
float hourangle = (((float)date.Hour) / 12) * 360 + date.Minute / 2;
hourangle += 180;
float minangle = (((float)date.Minute) / 60) * 360;
minangle += 180;
float secangle = (((float)date.Second) / 60) * 360;
secangle += 180;
hourAnim.From = hourangle;
hourAnim.To = hourangle + 360;
minAnim.From = minangle;
minAnim.To = minangle + 360;
secAnim.From = secangle;
secAnim.To = secangle + 360;
The Silverlight MediaPlayer
public void PlayMovie(object sender, MouseEventArgs e)
{
Canvas c = sender as Canvas;
MediaElement m = (MediaElement) c.FindName("mPlayer");
m.Play();
}
public void PauseMovie(object sender, MouseEventArgs e)
{
Canvas c = sender as Canvas;
MediaElement m = (MediaElement)c.FindName("mPlayer");
m.Pause();
}
public void StopMovie(object sender, MouseEventArgs e)
{
Canvas c = sender as Canvas;
MediaElement m = (MediaElement)c.FindName("mPlayer");
m.Stop();
}
DownloadProgressChanged="downloadProgressChanged"
MediaOpened="mediaOpened"
MediaEnded="mediaEnded"
public void downloadProgressChanged(object sender, EventArgs e)
{
}
public void mediaOpened(object sender, EventArgs e)
{
}
public void mediaEnded(object sender, EventArgs e)
{
}
public void timerComplete(object sender, EventArgs e)
{
}
MediaElement m = sender as MediaElement;
double width = Math.Floor(m.DownloadProgress * 448);
Rectangle rec = (Rectangle)m.FindName("downloadRect");
rec.Width = width;
Storyboard s = sender as Storyboard;
MediaElement m = (MediaElement)s.FindName("mPlayer");
if (isMediaOpened)
{
double percent = m.Position.Seconds /
m.NaturalDuration.TimeSpan.TotalSeconds;
double width = Math.Floor(percent * 448);
Rectangle rec = (Rectangle)s.FindName("playingRect");
rec.Width = width;
}
s.Begin();
isMediaOpened = true;
MediaElement m = sender as MediaElement;
m.Stop();
m.Play();
Let Silverlight greet you...
Enter your name:
...
private HtmlDocument document;
document = HtmlPage.Document;
HtmlElement btnOK = document.GetElementByID("btnOK");
btnOK.AttachEvent("onclick", new EventHandler(this.onOKClick));
private void onOKClick(object sender, EventArgs e)
{
HtmlElement input = document.GetElementByID("txtInput");
string text = input.GetAttribute("value");
txtHello.Text = "Hello " + text + "!";
}