Welcome to MSDN Blogs Sign in | Join | Help

And you thought the Olympic Silverlight app was Sexy?

Technorati Tags:

del.icio.us Tags:

Here's another Silverlight app that I've been bursting to share with y'all. It's from the promotion site for the 2008 Formula 1 Grand Prix being hosted in Singapore and sponsored by SingTel. It's a great and innovative use of Video. They are running a competition called the 'heart race' where 20 models will get your heart racing, but can you get theirs to race?image

The 20 models are laid out on screen as you can see on the left, and they are just doing their thing, hanging out, smiling, hoping that they catch your attention (these are video loops, the screen grab doesn't really do it justice). When you hover over one of the models, she gets excited, jumping up and down, like donkey in Shrek, inviting you to pick her. While this is going on, the other models get annoyed and stick their tongues out, show you a fist etc.

It's fun just mousing over the videos. I could do it for hours.

*ahem*

Anyway, back to the demo.

So, once you've found a model that you like (I know who my favorite is ;) ), you can select her to be taken into a questionnaire. The aim of the questionnaire is to see if you are a good match with that girl. Do you make her heart race too? If you do, there's a reward -- you'll just have to take the quiz to find out what it is.

 

One thing I really like about this app is the very simple, but very effective design. Look at this quiz screen:

 image

I really love how the simple color scheme works, how the names, bullets, buttons and girls outfit are all co-ordinated. By the way the girl on the right is a video, which again isn't really getting any justice with this screen shot.

Once you've answered the 10 questions, you get a score. If you match the girl, you'll get a little reward. If you dont, she doesn't look too pleased:

image

 

 

 

 

 

 

 

 

 

 

Also, if you share a friends name and email, there's another little reward. You'll have to try the app to see what it is, but let's just say that it involves DeepZoom ;)

image

So, what are you waiting for? Alexandra says 'Bring it on!'

2 Weeks of Olympic Spectacle are almost here!

Technorati Tags: ,,,

del.icio.us Tags: ,,,

When the Olympics were first awarded to Beijing, I have to admit that I was very skeptical. But I've been fortunate enough to spend a lot of time in China over the last couple of years, and I've seen how the preparation for the games has unfolded, and I am *impressed*. I have to say that I feel sorry for the folks in London, who are organizing 2012. They'll have a hard act to follow!

When it comes to technology, the Internet and the Olympics, there are a wealth of great sites. I want to use this post to show three of them.

  • NBC Olympics Silverlight-based Web Site
  • NBC Olympics On the go within Media Center
  • CCTV's Olympic site

NBCOlympics.com

image

 

First, is the NBC web site, powered by Silverlight. You can find this at http://www.nbcolympics.com. Select the video link and you'll see the new Olympics video site.

It's a really neat site, as you can see in the screen grab to the left.

Below the video player you'll see two tabbed areas -- the first is a set of related detail on the sports event you are currently watching. So, for example if you look at the screen grab, it's of a 100m sprint. The tabs then contain information about this race, it's history, the racers themselves and more. It's a one stop encyclopedic shop of everything that you might want to know, and it's right there at your fingertips.

The second tab pane is related video and trivia, again, keeping you right in the event. Great stuff. In addition, the page allows you to browse and search videos. You can see this on the right hand side. It's a great example of how to use AJAX and Silverlight to power a site.

But it doesn't end there -- click the 'Enhanced Player' option at the bottom RHS of the video to be taken to what must be the webs best and richest media player.

 

It gives you the following features:

Live Video Control Room: From here you can take a look at up to four live streams concurrently arranging them as a main video with 3 PIPs. These PIPs can be swapped in and out of the large view as well as being fullscreened.

 Olympic Sports: A one stop shop that allows you to browse the library of videos arranged by sport. I watched a great Korean movie the other day ("Our Finest Hour") about the ladies handball team in the 2004 Olympics. I then went to this screen and checked out handball, and sure enough the archive video of that fateful game was there. Warning, if you want to watch the movie, watch it first, or this player will spoil the ending! image

Most Watched: This screen helps you keep your finger on the pulse of what is hot right now. It's arranged in a fisheye/pyramidal view so you can see the top 10 things happening at the moment, as measured by their number of views. It's really cool if you want to stay up with the latest from the middle kingdom :)

As seen on TV:   No, it isn't trying to sell you steak knives or weight loss supplements. This screen, does exactly what it says it does, except it gives you a complete encyclopedic look at everything you might have missed off the goggle box. No DVR necessary -- the entire TV broadcast library is here right at your fingertips, arranged in a day-by-day view.

Highlights: This is very similar to the As seen on TV section above, namely that it breaks the Olympics down into a day-by-day coverage. Except in this case, it filters it down into the highlights. Don't have a lot of time, but want to know what is going on? Well this is the screen for you!

This application shows that design is much more than just pretty pictures and colors. It's also about understanding your users, understanding what they want to use, and how they want to access information, and making it as easy as possible to access. It's live right now, so go check it out at http://www.nbcolympics.com.

NBC's Olympics 'On the Go'

If you have a media-center equipped PC, then you've also got the option of the Free NBC Olympics 'On the Go' application. This is absolutely awesome! You can configure the sports that you want, and when video is ready, the app will download them to your media center. This means that you can stream them to an XBox 360 in your living room with the media center extender. Who needs PVR?

image

 

It's a snap to install and configure. And did I mention, it's FREE.

The video is available online, so if you have an edition of Windows that comes with Media Center, and you haven't use MC because of not having a capture card in your PC it doesn't matter. Fire that baby up, go to online media and follow the instructions. You'll install the app from TV Tonic's web site and you'll be off and running (pun fully intended)

To me it's a real killer application as it gives me the lean forward view (through Media Center on my PC) and the lead back view (through my XBox) in a consistent, clean and easy to use interface.

 

 

 

CCTVs Olympic Site

So as not to have an American bias, I also want to highlight what the locals will have in China insofar as the internet is concerned. CCTV are the national broadcaster of China, and naturally have the local rights to show the games.

They've built a nice site at http://www.cctvolympics.com.

As the games are in China, and thus in local prime time, I expect more people to watch them on TV than online, but for those who aren't near a computer, but instead near a PC, this site gives you some great options.

Live video is available, but CCTV have chosen an peer-to-peer architecture for relaying it. This makes sense, given the bandwidth issues that many people in China experience. In order to view live video you have to download a plug-in (on top of needing the Flash plug-in that is used to navigate to the content), that manages the p2p video. If you haven't seen p2p live video, it's an interesting concept, and very popular in China. The idea is that somebody seeds the p2p network with video, and every node in the network gets and receives packets of this video. The packets are assembled into a local server, and then Windows Media Player streams the video from this server. The video is thus streamed from http://localhost:port or http://127.0.0.1:port. It's a common p2p player architecture in China. For similar players, take a look at sopcast, pplive, ppstream etc.

This is one of the nice advantages of the Silverlight site for the NBC. As it doesn't need or use a p2p player, it can use a cross-browser, cross-platform Silverlight application, thus allowing it to work on FireFox on the PC as well as FireFox and Safari on the Mac. It's a little ironic that the Microsoft based offering works on FireFox, but the Flash based one does not! (At least for Live Video)

Perhaps more interesting are the social elements of the site. This is natural for China, as the site is likely to be less of a destination for watching the Olympics and more of a destination for interacting around the Olympics, due to the fact that the locals don't have the time-difference that we in the USA do, so they can watch the games on TV in the evening and then interact around them the morning after!

As such the site has plenty of games to play, and social interaction built around Windows Live ID and Windows Live Messenger. When you sign in with these, you can chat around the current thing you are watching, putting yourself literally 'on the map' by letting the work know where you live.

The spirit in China has been of hospitality, and of 'One World, One Dream'. The social nature of the CCTV application has been in empowering this. It's a beautiful example of Software and a Service (SaaS), where the back end services from Microsoft are empowering and interoperating with a front end technology from one of our competitors!

Unfortunately I cannot provide a screen shot of it at the moment, as the PC I am writing this on did not have Flash installed. I followed their links to the Adobe site to install Flash, which gave me 9.x, but the detection script on the CCTV site doesn't seem to like this version....sorry about that.....

Read about Silverlight in XPS

del.icio.us Tags:
     
Technorati Tags:
      
BuzzNet Tags:

I've adapted David Anson's XPS Viewer for Silverlight sample to allow you to read the first 3 chapters of my Silverlight 2 book using a SIlverlight/XPS experience. As part of this sample I added some code to support the mouse wheel. As you can see it makes for a very nice document viewing experience on the web. I'm thinking of enhancing this further by adding ink and collaboration.

Of course it's all about getting the time to do it, right! :)

You can see a sample of it in the iFrame below, or click here to see the full reader.

Introducing Silverlight 2: Table of Contents and bonus chapters!

 

Technorati Tags:

del.icio.us Tags:

Lots of folks have been asking me for a TOC for the Silverlight 2 book, so here it is. The book is divided into 2 parts (Introducing Silverlight 2, and Programming Silverlight 2). Note also that there are some upcoming bonus chapters that will be a download for readers. These will include chapters on Visual State Manager, More Controls, Install UX and more on Networking including sockets and duplex:

 

Part 1: Introducing Silverlight 2.

Chapter 1: Introducing Silverlight 2:

This Chapter introduces Silverlight, what it is, what it does, what its Architecture is and more. It talks about XAML and why XAML was designed. It also introduces the Expression suite, including Design, Blend and Encoder. You'll see how to build your first Silverlight application -- a media player.

Chapter 2: Expression Blend and Silverlight 2:

Using the Expression Blend design tool to build Silverlight experiences. You'll be given a tour of the tools and a taste of what you can do with them! You'll also see how Expression Blend wizards create the Web page and all associated files that you'll need to deliver Silverlight to your users.

Chapter 3: Using Visual Studio with Silverlight 2:

How to install and use the Silverlight tools and SDK. You'll then be taken step-by-step through building a casual game.

Chapter 4: XAML Basics:

So you've been playing with Silverlight 2 to build apps, and you've used Blend. These have been generating your UI using and XML variant called XAML. Here's a tool of XAML that will get you very familiar with the basics of it.

Chapter 5: XAML Transformation and animation.

XAML is very useful for defining your UI -- but it is much more powerful than just UI layout and controls declaration. You can also declaratively define how your UI can transform over time, and define timeline-based animations easily in XAML. THis chapter shows you how. Incidentally, an excerpt from this chapter has been published in the August 2008 copy of MSDN magazine.

Chapter 6: The Silverlight Browser control.

Everything you wanted to know about the browser control but was afraid to ask! This details the control itself, how to use it in a page and how to program against it using JavaScript.

 

Part 2: Programming Silverlight 2.

 

Chapter 7: Silverlight Controls: Presentation and Layout

This chapter will tour you through the most commonly used controls in Silverlight, namely the Button, Checkbox, HyperlinkButton, Image, ListBox, RadioButton, TextBlock and TextBox controls. You'll look at the main use-case for each of these controls and investigate their most commonly used properties, methods and events. You'll also build some sample applications that demonstrate them, as well as how to use control extensions such as IME with the TextBox.

 

Chapter 8: Silverlight Controls: Advanced Controls

This Chapter will go into some of the more sophisticated and useful controls that are available in Silverlight 2. It includes the DataGrid, Calendar, DatePicker, RepeatButton, ToggleButton, ScrollViewer, Slider and more. It goes through the typical usage of each of these, and will help you get up and running quickly with using them.

 

Chapter 9: Building your own Silverlight control

A great feature in Silverlight is its extensibility. This chapter will take you step-by-step through building your own control by subclassing an existing one.

 

Chapter 10: Building Connected Applications with Silverlight

Let's face it, an application without connectivity, will, regardless of how cool it is, grow stale quickly! In this chapter you'll look at connectivity scenarios, where you can deliver Silverlight from, and connect Silvelright to server technologies such as Java (JSP), PHP and of course ASP.NET!

 

Chapter 11: Media, Ink and DeepZoom

The title says it all. This chapter drills down into programming using these three technologies. You'll do a lot of media work, looking at the Silverlight Media APIs for managing everything from buffering to adding interactivity to your media application using markers. With Ink, you'll get a ramp-up on how to use the Ink APIs to allow tablet users to interact with you app. Finally, with DeepZoom, you'll go into the ins-and-outs of building a multi layered deep zoom application (where you zoom into a picture in a picture in a picture etc.). If you've seen the 'Hard Rock Cafe' demo, you'll see how some of the fancy tricks in that were built.

 

Chapter 12: Styles and Templates

This chapter will give you an introduction into how to build reusable and interchangeable styles for your Silverlight controls. In addition it will show how these can be brought together into templates.

 

Chapter 13: Silverlight ASP.NET Controls

This chapter details the ASP.NET controls that ship with the Silverlight SDK and how they can be use to deliver Silverlight in an easy manner without you having to twiddle with HTML. Additionally it details the Silverlight media control that allows you to deliver a ready-baked media player for Silverlight media.

 

Chapter 14: Dynamic Languages and Silverlight

This chapter details the new DLR in Silverlight that allows you to program rich UI applications using IronPython, IronRuby or Managed JavaScript. If you've been wondering about these, and have been loooking for a good place to dip your toe in the water -- this is it.

 

Coming Soon, for readers only, bonus chapters on Visual State Manager, Building a great Install UX, Enhanced Networking including Sockets programming, More Controls and more....

Introducing Silverlight 2: If you're having problems with the code...

del.icio.us Tags:

Technorati Tags:

After the book was published, Microsoft issued an update to Beta 2 with some bug fixes etc. In addition, these came with a number of updated tools and VS plug-ins that revved up the Project version #. Unfortunately this has had the effect of breaking a number of the code sample projects in the book as they were built using the original Beta 2 release.

Watch this space...I'm updating all projects and source to work with the latest release and will make it available to download here and on the books official website. Hopefully before Monday 7/28.

Introducing Silverlight 2 Book now available

del.icio.us Tags:
     
Technorati Tags:

 

My Silverlight 2 book is finally available!

Amazon's page for this book is a little confusing, so I thought I'd clear some stuff up :)

Despite the title, this is the First edition of the book for 'Introducing Silverlight 2'. For some reasons, the previous book 'Introducing Silverlight 1.0' is being counted as the first, and this book as the second, but it's a completely different book for a completely different version of Silverlight!

Secondly, it's Silverlight 2, and not Silverlight 2.0 :)

Third, and most important -- it is based on the Beta 2 of Silverlight 2. It was revised and updated using daily builds of B2, so there may be some small differences between it and the actual Beta 2 release. If you find any gotchas, or if anything is holding you up -- drop me a line at lmoroney@microsoft.com.

This book will be kept up to date so if you want to get started with SL2, don't wait for the RTM version of the book, go with this one. Code updates for CTP/RTM, bug fixes etc. will be posted to my blog at http://blogs.msdn.com/webnext.

Finally, I think this is a _great_ book to help you demystify Silverlight. I've tried to make it as easy to read and approachable as possible. It's not an in-depth exhaustive tree-killing tome. My goal was to give you a book that you can skim through and dive into in a week or so, and have enough to be up and running with this wonderful technology! As always I appreciate feedback, and reviews on the Amazon page (particularly positive ones!!)

The book is in two parts, the first, introducing Silverlight where I go over the architecture of Silverlight, how to use it in the browser, what XAML is all about, how to use JavaScript to program Silverlight and more.

The second part, 'Programming Silverlight' gives you a detailed introduction to programming Silverlight using .NET. I give you an intro by building a casual game, then move onto looking at the common controls that you may want to use in Silverlight. I've also put in a chapter on how to build your own controls.

Additionally Media, Ink, DeepZoom, templates, Dynamic languages, ASP.NET controls and more are covered. I know I'm biased, but I think this is a great book.

Finally, the book is being translated into Chinese, Korean, Japanese and French, which is particularly exciting. Can't wait to see the final versions of each!

Please check it out!!

Silverlight 2 Beta 2: Available very soon

Technorati Tags:

del.icio.us Tags:

We're just wrapping up the final details for Silverlight 2 Beta 2. It should be available to download very very soon, so keep your eye on http://www.silverlight.net for details.

There's lots of new features in this release -- including, but not limited to:

  • UI Framework -- we've made lots of improvements to the animation support, error handling, accessibility, keyboard input and general overall performance. This is intended to bring us more in line with WPF and improve overall compatibility between the two. It also allows your skills in one to more easily transfer to the other.
  • Controls - We have a few new controls, such as a Tab control, as well as goodies like text wrapping and scrollbards for the TextBox and Autosize, Reorder, Sort etc. for the DataGrid.
  • Networking and Communications -- Cross Domain is further improved over beta 1, the WebClient has been updated to allow uploads, and duplex communications ('push' from server to SL) have been added. This should make for some very interesting scenarios
  • Deep Zoom -- this has been hugely updated. The file format is now XML instead of a binary format, so the ability to generate your own Deep Zoom images and collections server side will become easier. There's also some nice new event models around zoom/pan state.

More to follow...

Posted by lmoroney@microsoft.com | 1 Comments
Filed under:

Building A Casual Game in Silverlight

Technorati Tags:

del.icio.us Tags:

If you attended MIX08 you would have had a free sample copy of my Silverlight 2 book in the attendee bag. The book has 3 chapters, one on XAML, one on Silverlight 2 in Visual Studio and one on building Silverlight 2 controls.

Frankly, I sometimes wonder why I spend so much time writing books on technology (it's certainly not for the money, unless you have aspirations to be a thousandaire), but occasionally someone comes along and makes my day.

Cigdem Patlak Uzun (aka Crocus Girl) has doen this by taking the sample sliding blocks puzzle from my Silverlight 2 book and turned it into a proper casual game. She's done a terrific job, and its well worth checking out.

Click the image here for more.

She's turned my simple 4x4 grid with a fixed picture into one that can be 4x4 or 2x2, as well as having the facility to upload your own pictures. It keeps track of your cumulative moves to give you a 'score' and has a much prettier UI (not to mention picture) that the one that I used!

Cigdem's blog is a great read, you can find it at http://crocusgirl.wordpress.com. If you have any questions about the app (and maybe want the source code?) get in touch with her there :)

 

Nice job Cigdem!!! :)

Search::Redefined - Silverlight and Yahoo! Japan

I spend a lot of time and miles evangelizing Silverlight, and sometimes it can be painful to see the amazing things that are being done with it, but that I cannot share until they are ready to go.

One such has been what I have been working on is with Yahoo! Japan. Finally it can see the light of day. Yahoo! Japan are the biggest website in Japan, and with typical Japanese flair they want to redefine the entire search experience.

Well they've done it. I can't wait to see more sites innovating like this.

Anyway, take a look here: http://www.microsoft.com/japan/products/expression/creatorsEX/gallery_y.html

...and you'll see it in action. View the video at the bottom of the page.

The live site should be ready to go in a few weeks, but watch the video and see what they've been doing.

Makes the typical search experience of a text block followed by a list of flat HTML text seem boring now, doesn't it? :)

Ganbarre!

 

gallery_y_01_lgallery_y_02_l

Silverlight: Great showcase of Silverlight 1 wins, and information on updates...

Technorati Tags:
   
del.icio.us Tags:

While many among you are focusing more on Silverlight 2, I still strongly recommend that you look at Silverlight 1 for your development needs. If you weren't at MIX, there's a great showcase video (on youtube no less) that shows some of the terrific stuff that is already out there on Silverlight 1.

Here it is:

There's some great stuff in here, my favorite I think being the Korean MNET site, which provides a Silverlight front end to 2million+ pop videos, providing unintrusive advertising, interaction, search engine, Korean IME, styling and more.

And this was build in Silverlight 1!!!

So, if you want to get ahead on SL2 development, there's plenty of goodness that you can deliver today on the RTM Silverlight 1.

Additionally, we've released several service releases of Silverlight 1 since September. Details of them can be found at the following links:

Release History

· Silverlight 1.0 GDR (build 1.0.30401.00) Released April 4, 2008

· Silverlight 1.0 GDR (build 1.0.30109.00) Released Jan. 15, 2008

· Silverlight 1.0 GDR (build 1.0.21115.0) Released Nov. 20, 2007

· Silverlight 1.0 (build 1.0.20816) Released Sept. 4, 2007

Related Links

Enjoy!

Live IT : I'm speaking at Tech ED Israel Tomorrow

If you happen to be hanging out in Eilat, Israel tomorrow, I'm speaking on 'Go Gold With Silverlight' tomorrow afternoon at 2PM local time. I'll be going into detail on what Silverlight is, and where it fits in with Microsoft's overall UX strategy. I'll be focussing on the connectivity aspects in Silverlight 2, showing some demos of how Silverlight can interact with various server technologies including using AJAX and J2EE. It should be fun! I did the Silverlight part of the keynote today with a Mac on stage, and tomorrow I'll be coding in Java. I'm afraid that they'll throw me out!!! ;)

Some pictures: http://www.flickr.com/photos/techedisrael/

And for some R&R, Eilat has a place that you can go swimming with Dolphins....cool, huh? http://www.dolphinreef.co.il/Default.aspx?tabid=27

A quick note on Silverlight Evangelism...and a great blog on Business Development of Silverlight

del.icio.us Tags:

Technorati Tags:

Working for Microsoft is something that I'd recommend to anyone that is interested in technology. I work with the Developer Platform Evangelism team, which, if you're a geek like me, is a great place to be because it lives at the intersection of the Product Development, Marketing and Business Development axes.

The former of these two are probably well know to the masses of developers, designers, devigners and deselopers among you, but I get many questions about what is involved in the third. Too many times I've had conversations with friends to say "No, it's not being a salesman!" , so now my colleague and friend Chris Carper, a member of the Silverlight business development team has started a blog on Silverlight bizdev. Check it out at: http://silverlightbiz.blogspot.com/

Posted by lmoroney@microsoft.com | 2 Comments
Filed under:

Silverlight Dynamic Languages in Visual Studio

    

Silverlight's support of Dynamic Languages is really cool, but, as there is no template in Visual Studio or Expression Blend that supports them it might be a little difficult for you to get up and running quickly. So, I wanted to put together this blog posting to show you how you can use them within Visual Studio in a common (or garden) Web site project. It's a pretty lengthy tutorial for a Hello World applicaiton, but I'm assuming that you are as unfamiliar with Dynamic Languages as I was when I started figuring them out.

It's something I've been working on for my Silverlight 2 book, Hope you like it! Do note that all proceeds from this book will go to children's education(*), so be sure to buy lots of copies.

Silverlight 2 adds support for the use of dynamic languages, which are defined as programming languages that execute many features at runtime that other languages such as C# execute at compile time. Such behaviors include things such as extending objects and definitions, modifying the type system and more. This approach is designed to give dynamic languages a simple approach for learning through a ‘run-evaluate-print’ loop with lots of trial and error as you develop.

Silverlight 2 supports three of the more popular dynamic languages: Ruby, Python and dynamic, managed JavaScript. The SDK provides a tool called Chiron.exe that allows you to work with dynamic languages.

 

(*) My children's education of course! :)

 

Getting Started

The Chiron tool is easiest to use if you have a specific application directory structure set up for your application. In this section we’ll go through how to do this step by step.

First launch Visual Studio and create an empty Web Site by selecting New Web Site from the File menu. You’ll see Empty Web Site as an option on the New Web Site dialog.

clip_image002

 

This will create an empty directory that Visual Studio can access as a Web Site. However, we will be using Chiron to run the site, but creating the pages, code etc is easier in Visual Studio.

From the Solution, right click on the project folder and select ‘Add New Item...’ – this will give you the Add New Item dialog that you can use to create a new HTML page, so select the HTML page option and give it the name Default.html.

clip_image004

 

This will give you a basic HTML page, which you should edit to turn into a page that will host the Silverlight application. Here’s the code for such a page.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Dynamic Silverlight Test Page </title>
  <style type="text/css">
    html, body {
      height: 100%;
      overflow: auto;
    }
    body {
      padding: 0;
      margin: 0;
    }
    #silverlightControlHost {
      height: 100%;
    }
  </style>
</head>
<body>
  <div id="silverlightControlHost">
<object data="data:application/x-silverlight," 
    type="application/x-silverlight-2-b1" 
    width="100%" height="100%">
      <param name="source" value="app.xap"/>
      <param name="background" value="white" />
      <param name="windowless" value="true" />
    </object>
    <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
  </div>
</body>
 

This uses the <object> tag approach to host Silverlight in the page. It’s bare bones, so doesn’t include the code to provide an install experience if Silverlight isn’t present on the system.

Keep a note on the source parameter which is set to app.xap. Chiron will build this for you, which you’ll see in a moment. In order for it to have this name, your code file will need to be called app. First you’ll look at how do build your application with IronPython, and an app.py file, and later you’ll see how to do the same functionality with IronRuby and Dynamic JavaScript.

Next, create a directory within your web called app. Within this, select ‘Add New Item’, and select the XML File template, and call the file app.xaml.

Here’s some simple XAML that you can put into this file:

<UserControl
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="System.Windows.Controls.UserControl"
    x:Name="Page"
    >
  <TextBlock
     x:Name="txtMessage" TextWrapping="Wrap" 
     Foreground="Black" Text="Hello World," >
  </TextBlock>
</UserControl>

This defines a simple UserControl object that contains a TextBlock called txtMessage. This TextBlock contains the text “Hello World,” – note that it ends with a comma. You’ll see why in a moment!

Now let’s add the IronPython code file. Again right click on the app folder within your Web site, and select ‘Add New Item…’. From the dialog, select Text File and call it app.py (‘py’ is the extension for python).

As a quick sanity check your solution should look like this:

clip_image006

Now let’s edit your python code file to make it do something a little interesting.

Here’s the code:

from System.Windows import Application
from System.Windows.Controls import UserControl
 
def handleClick(sender, eventArgs):
    sender.Text = sender.Text + " from Python!"
 
class App:
    def __init__(self):
        self.scene = 
          Application.Current.LoadRootVisual(UserControl(), 
                                             "app.xaml")
 
    def start(self):
        self.scene.txtMessage.MouseLeftButtonUp += handleClick
        
App().start()

If you’ve been writing Silverlight applications in C# or VB, the syntax will be roughly familiar to you, so for example the line

from System.Windows import Application

is equivalent to the C#

using System.Windows;

and then referring to the Application class in code.

The code then defines a python class, called App and sets the ‘scene’ object for this app by loading the xaml file that you defined earlier. As part of this class definition it defines the startup event hander with def start(self): and specifies the code to execute within this handler. This code defines the event handler for the MouseLeftButtonUp event on the TextBlock control called txtMessage that you defined earlier. The event hander is called handleClick.

The event handler code itself is here:

def handleClick(sender, eventArgs):
    sender.Text = sender.Text + " from Python!"

This adds the text “ from Python!” to the end of the Text property of its sender (which in this case is the TextBlock) upon being called.

Configuring Visual Studio to use Chiron

To run this application you’ll use Chiron. You can configure Visual Studio to launch Chiron by right clicking on the project file in Solution explorer (note, use the Project file and not the Solution file – the Project is usually the first child of the Solution) and selecting Property Pages from the pop up menu.

From the property pages, select Start Options, and then select Start external program. Use the ellipses button to brose to the location of Chiron.exe which should be in C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Tools\Chiron.exe.

Enter ‘/b’ in the Command line arguments setting, and then enter the location of the web site in the Working Directory setting.

You can see it here

clip_image008

 

Now you can execute your dynamic Silverlight application by pressing F5 in Visual Studio.

Chiron will launch and you’ll see this in a command prompt window:

clip_image010

This shows you that the application is accessed via http://localhost:2060. Visual Studio will also launch a browser at this address, which gives you a listing of the files within the web directory.

clip_image012

Select Default.html to see your dynamic Silverlight application. You’ll see your ‘Hello World’ message.

clip_image014

Clicking the ‘Hello World,’ text will then add ‘ from Python’ to the block as shown here

clip_image016

While this is, of course, an extremely simple application, it demonstrates how the Dynamic Language Runtime works in Silverlight, and how to configure Visual Studio to use Dynamic Languages!

Posted by lmoroney@microsoft.com | 3 Comments
Filed under:

Determining Silverlight Installation Metrics at your site

del.icio.us Tags:

Technorati Tags:

Following lots of requests from folks inside MS, I wrote this paper as a very simple guide to determine installation metrics. No reason why it shouldn't see light of day, so share and enjoy! :)

 

Introduction

This paper is intended to provide a methodology for customers to measure the level of Silverlight adoption amongst their customer base. Silverlight does not write to the HTTP_USER_AGENT string, so server logs will not contain any direct data for Silverlight installations. However, a very straightforward process may be used on web pages on the customer site to determine Silverlight penetration. This paper discusses two of these methods.

Overview.

The procedure is very straightforward. In both cases, client-side JavaScript and Dynamic HTML are used. The JavaScript is used to detect the presence of the Silverlight plug-in on the browser. The server hosts two images, one which is loaded if Silverlight is present, one which is loaded if Silverlight is not.

In this example, the images are called ‘red.gif’ and ‘green.gif’. Server logs can be used to see the traffic to each of these images. If R is the total traffic to ‘red.gif’ and G is the total traffic to ‘green.gif’, then R+G is the total traffic and [100* G/(R+G)] gives us the total percentage of traffic that comes from browsers with Silverlight installed.

Please note that these samples use red.gif and green.gif for illustrative purposes only. In a production system, it is recommended to use a 1 pixel by 1 pixel image which is not visible to the user.

[The assumption being made here is that R and G can be measured in Unique Users (UU)]

Method 1 – Using Silverlight.js.

This method involves the customer putting ‘Silverlight.js’ on their site. This JavaScript library is approximately 8Kb in size, and contains functions that are heavily tested across different browsers and operating systems.

It includes a variable: Silverlight.available which evaluates to True is Silverlight is installed and False if Silverlight is not.

This can then easily be used within HTML like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Silverlight Test Page 1</title>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function doTest()
        {
            if(Silverlight.available)
            {
                imgContent.innerHTML = "<img src='green.gif' />";
            }
            else
            {
                imgContent.innerHTML = "<img src='red.gif' />";
            }
        }
    </script>
</head>
<body onload="doTest()">
    <div id="imgContent"></div>
</body>

</html>

This HTML contains a DIV element called imgContent. Upon the page loading, the doTest() function is called. This checks to see if Silverlight is available. If it is, it sets the innerHTML property of imgContent to contain an HTML Image element that has its source set to the URL of either the red or green image. This generates a call to the image, and thus loggable traffic on that image.

The logs can then be inspected as outlined in the overview section.

Method 2 – No Silverlight.js

A similar approach may be taken if Silverlight.js is not present. The advantage of this is that the customer does not need to distribute or update the Silverlight.js file. The disadvantage is that it is a little more complex, and will require maintenance as new Silverlight versions, browser versions, and operating systems platforms are supported.

It follows a similar approach to method 1 in that it determines if Silverlight is installed. If it is, then the imgContent div will have its innerHTML set to an image referencing the green.gif URL, otherwise it will be set to an image referencing the red.gif URL.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Silverlight Test Page 2</title>
    <script type="text/javascript">
    function doTest()
    {
        var container = null;
        try {
            var control = null;
            if (window.navigator.userAgent.indexOf('MSIE') >= 0) {
                // For Internet Explorer, Create an ActiveX Object
                // And assign it to the 'control' variable.
               // If Silverlight is not installed, this should throw an error
                control = new ActiveXObject('AgControl.AgControl');
            }
            else {
             // For FireFox/Safari
             // Check to see if the plug-in is present
                    
             if (navigator.plugins['Silverlight Plug-In']) {
             {
                container = document.createElement('div');
                document.body.appendChild(container);
                container.innerHTML= 
                   '<embed type="application/x-silverlight" src="data:," />';
                control = container.childNodes[0];
            // If the plug-in is present, then we should have gotten this far
            // without an error. If we threw an error, it is caught later on
             }
             else
             {
                        // plug-in is not present, so we go red
                        imgContent.innerHTML = "<img src='red.gif' />";
             }
            }
           }
           if (control) {
                // plug-in is present and we were able to instantiate
                imgContent.innerHTML = "<img src='green.gif' />";
           }
           else
           {
                // we weren't able to instantiate, so we say it isn't present
                imgContent.innerHTML = "<img src='red.gif' />";
           }
         }
        catch (e) { 
            // we hit an error so we say it isn't present
            imgContent.innerHTML = "<img src='red.gif' />";
        }

        // Let's clean up
        if (container) {
           document.body.removeChild(container);
        }

    }
    </script>
</head>
<body onload="doTest()">
        <div id="imgContent"></div>
</body>
</html>

As can be seen in the code, the approach is to try to create an instance of the plug-in on the page using DHTML. If this fails, or if the plug-in is found to not be present by checking the browser-dependent methods, Silverlight is deemed to be not installed. If it succeeds, Silverlight is deemed to be installed. The appropriate ‘red’ or ‘green’ URL calls are then made, and their logs can be checked against in the way discussed in the overview.

Summary

This paper discussed two methods for determining Silverlight penetration at a client site, by using web pages with JavaScript and Dynamic HTML. The first approach used libraries within Silverlight.js, and the second bypassed using this file. At time of writing the first approach is recommended as the Silverlight.js library is fully and extensively tested for cross-browser and cross-platform correctness, and thus the most accurate results may be attained.

Posted by lmoroney@microsoft.com | 2 Comments
Filed under:

DeepZoom in C# - Not just possible, but easy

DeepZoom with the MultiScaleImage control

Technorati Tags: ,,

del.icio.us Tags: ,,

 

DeepZoom is a new technology which has been added to Silverlight 2 which gives you a new and unique way of managing images within your application. It is implemented by the <MultiScaleImage> element in XAML, which, as its name suggests, gives you the facility to control scale and zoom of your images, with Silverlight providing a huge virtual space on which these images can be drawn.

This is best described by example. Here you can see an image of a kids science project.

clip_image002

Now this doesn’t really look too fancy. So what’s all the fuss. Well, on this application if you drag the mouse wheel, you can zoom in or out. So, if you look at the next figure, you’ll see another view of this where I’ve zoomed out of the orange, and am showing where this image is relative to another image.

clip_image004

 

If you look closely at the center of the orange above, you’ll see that the first image is embedded within the orange at the center. You can zoom out from this again, to get this image

clip_image006

 

As you can see the entire second image is little bigger than a pixel in the third image, and the entire first image is little bigger than a few pixels in the second. It’s hard to do this justice with these stills, but it has to be seen to be believed, and when you play with it, you’ll see why the technology is called DeepZoom…it allows you to arrange pictures so that you can zoom in and out of them very easily, painting them on a giant, scalable canvas.

Using the Deep Zoom Composer

But how do you build an application like this? It’s pretty simple to do a basic one – you simply use the MultiScaleImage control and point it at a .BIN file that contains metadata about the images. You create this .BIN file using the DeepZoom composer tool, which may be downloaded from the Microsoft Download center.

You can see the composer tool here:

clip_image008

This tool follows a simple workflow of Import followed by Compose followed by Export.

So, first you should select the Import tab, and select ‘Add Image’ to pick a picture, and repeat for the number of pictures you want to use. You can see in Figure 11-21 that I’ve selected three images.

The next step is to Compose, which you will do with the compose tab. On this tab you place images on the design surface and then zoom in and out and place others. So, for example if you look at Figure 11-22, you’ll see where I’ve placed one image and zoomed into the eye.

clip_image010

Now if you place a new image, it will be placed at its normal resolution once the Silverlight component is zoomed to the level that you are currently at in the composer. So if you look at the next picture, you’ll see where the image has been placed within the eye. Later, when you run the application, you would have to zoom directly into the eye to see this image, and it will be tiny until you zoom further into it. clip_image012

In this simple example we’ve just added one image to appear when zoomed in on another. The tool allows us to build far more complex applications, but for the purposes of this sample, what we have will do. We are now ready to go to the third step – exporting the details.

You can see this here:

clip_image014

To do this, you simply need to give the project a name and export it to the specified location.

Once this is done, you’ll see two files and a folder created in the output directory. The first file is the project file for the Deep Zoom composer. The second is SparseImageSceneGraph.xml which is a configuration file that simply defines each image and the location of each image within the other in the different Zoom levels. So, for example you can see the scene graph for the 2 picture XAML here:

<?xml version="1.0"?>
<SceneGraph version="1">
  <AspectRatio>1.33333333333334</AspectRatio>
  <SceneNode>
<FileName>C:\Code\SLBook\Chapter11\DZCSample
     \source images\DSCN2961.JPG</FileName>
    <x>0</x>
    <y>0</y>
    <Width>1</Width>
    <Height>1</Height>
    <ZOrder>1</ZOrder>
  </SceneNode>
  <SceneNode>
<FileName>C:\Code\SLBook\Chapter11\DZCSample
     \source images\DSCN2959.JPG</FileName>
    <x>0.451782754964542</x>
    <y>0.313488814592021</y>
    <Width>0.00099432659277551</Width>
    <Height>0.00099432659277551</Height>
    <ZOrder>2</ZOrder>
  </SceneNode>
</SceneGraph>

It’s pretty straightforward. It contains the aspect ratio for the master image (derived from the dimensions of the first image) and then each image becomes a SceneNode. The first image is the first scenenode, and it is defined as being located at position 0,0, and is a normalized image – i.e. its width and height are set to ‘1’. All other image sizes and locations are then set relative to this. The second image, as you will see is at approximagely 0.45 on the x axis, and 0.31 on the y axis and is sized at approximately 0.00099 on X and Y relative to the first image, thus if you zoom into the first image to approximately 10,000x the original size, you’ll see the second image. It is ZOrdered at 2 (while the first is at 1), meaning that it will be drawn on top of the first image.

In addition to this, the Deep Zoom composer slices the image into tiles so that you don’t have to load every tile for every zoom level, giving you nice efficiency when you are dealing with large images. When you are zoomed out, you will have a ‘small’ tile, indicating the apparent resolution for being zoomed out. When you zoom into the full resolution of the image (or beyond), you will only see a portion of the image, and thus you will only get the tiles representing the part of the image that you see, thus saving bandwidth and download time. The Info.bin file contains all the details of the tiles and where they are relative to the main image. You’ll find it in the subdirectory, along with a number of other directories containing the images.

Building your first Deep Zoom project.

To use this in an application, create a new Silverlight Application. Before doing anything, you should compile the default application. This will create the ClientBin application in the Web Application part of the solution. When this is done, close the solution.

Now, use Windows Explorer to copy the directory containing the info.bin file and the subdirectories containing the fragmented images into the ClientBin directory of the web application. When this is done, re-open the solution. You should see your project explorer will look something like this:

clip_image016

Now to render the Deep Zoom content, you simply add a MultiScaleImage to your Page.xaml, and set its Source property to the location of the info.bin file (in this case it is in /dzcsample/info.bin), as well as its desired width and height.

Here’s what your Page.xaml will look like:

<UserControl x:Class="DZCSampleApp.Page"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Canvas>
        <MultiScaleImage Source="dzcsample/info.bin" 
          Height="300" Width="400" />
    </Canvas>
</UserControl>

So now when you run this application, the MultiScaleImage control will render the top element in the SceneGraph, zooming into it from a 1x1 picture to the width and height specified (400x300 in this case).

You’ll notice that there is no automatic mouse activity, so you cant pan or zoom the image. We’ll look at how to do this in the next section.

Using the Mouse and Logical Co-Ordinates in Deep Zoom

The MultiScaleImage is just like the other components in Silverlight in that it can declare the functions that should be used to handle events. So, to pan around the image you will use the typical mouse events of MouseLeftButtonDown, MouseLeftButtonUp and MouseMove in a very similar manner to drag and drop on any control.

So first, lets take a look at the XAML for the MultiScaleImage that defines these events:

<UserControl x:Class="DeepZoomSample.Page"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="640" Height="480">
    <Canvas>
        <MultiScaleImage x:Name="dz" Source="dzcsample/info.bin" 
            MouseLeftButtonDown="MultiScaleImage_MouseLeftButtonDown" 
            MouseLeftButtonUp="MultiScaleImage_MouseLeftButtonUp" 
            MouseMove="MultiScaleImage_MouseMove" 
            Height="480" Width="640"></MultiScaleImage>
    </Canvas>
</UserControl>

And now we’ll look at each of these event handlers in more detail. First, there’s some code that is shared across them all, and used for tracking the current state of the mouse and the currently viewed co-ordinates of the MultiScaleImage.

bool dragging = false;
 
double dx = 0;
 
double dy = 0;
 
Point p0;
 
Point p1;
 
Point pLast;

 

So now, let’s examine what happens when the user presses the mouse button on the image:

private void MultiScaleImage_MouseLeftButtonDown(
    object sender, MouseButtonEventArgs e)
        {
            dragging = true;
            p0 = dz.ElementToLogicalPoint(new Point(0, 0));
            p1 = dz.ElementToLogicalPoint(new Point(640, 480));
            dx = 0;
            dy = 0;
            double x = e.GetPosition(null).X;
            double y = e.GetPosition(null).Y;
            pLast = dz.ElementToLogicalPoint(new Point(x, y));
            
        }

So, when the mouse button is held down, you are going to assume that the user is dragging the mouse, so we set the dragging Boolean to true. Then we want to get the current co-ordinates of the image that are visible. Remember that the top image is defined as being at x=0 and y=0, and that its width and height are both set to 1. These are the logical co-ordinates and the logical dimensions.

In Silverlight if we want to derive the logical co-ordinates of the top left of the window and the bottom right, we can get them by using the ElementToLogicalPoint method. If you pass a physical co-ordinate to this, the logical result will be returned. So, if you can imagine that you are zoomed into a picture and you’ve panned that picture around a little, then if you call this API for physical point (0,0) – i.e. the top left of what you can see then the logical point representing that location on the full image will be returned. To get the bottom right you do the same for the point at the current width and height of the physical display (in this case 640x480).

We want to track how much we’re changing on X and Y, so we set the variables dx and dy to zero. We’ll see more of this in a moment.

Finally we’ll also want to get the logical co-ordinates of the mouse pointer, so we do this with the ElementToLogicalPoint API call and passing the current mouse position (which can be derived from the MouseEventArgs object that is passed to this function), and load the results into the pLast variable.

Now that the mouse is down, once we start dragging what happens next? We want the image to pan around and follow us. Here’s the code to achieve this:

 

The MouseMove event will fire whether the button is held down or not, so we use the dragging variable to indicate whether or not we’re dragging. So, if we’re presently dragging, and if we presently have some event args, the rest of the code will execute.

In this case we pull the current co-ordinates of the mouse and assign their logical equivalents (received using the ElementToLogicalPoint method of the con