Silverlight Brass Tacks

Bill Reiss' Silverlight Ramblings
My upcoming Silverlight book for beginners Hello! Silverlight 2 with Dave Campbell, available online now!



Pages

Recent posts

Navigation

Archive

Blogroll

Tampa Divorce Lawyer

North of Tampa in Lutz, Florida. A Tampa Divorce Lawyer focusing on family, divorce, and real estate law.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Looking for Silverlight/Cloud/Online Services speakers at South Florida Code Camp 2009

Code camps are a great way to get into the world of speaking if you're a first timer or haven't done it very much, and the South Florida Code Camp on Feb 7, 2009 is one of the biggest in the nation. With 12 tracks and over 600 attendees, there's something for everyone.

I'm the track chair for the Silverlight/Cloud/Online Services track. With the holidays and other commitments I haven't really had time to solicit speakers so my track has a couple of open spots right now. So whether you're interested in speaking on one of these topics or on something else, you can get more details on how to register as a speaker here:

http://codecamp09.fladotnet.com/SpeakerRegistration.aspx

Being in the Miami area for the second weekend in February isn't such a bad deal, so if anyone up north wants to make a long weekend out of it you're welcome as well.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Jan 05 2009, 05:25 by Bill Reiss | Comments (3) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Converting C# samples to VB.NET

It seems that all of the good samples out there for Silverlight or any other .NET technology are written in C#. So f you’re a VB.NET developer, what are you to do?

There are some good tools out there to convert C# code to VB.NET, some are very good and cost a good deal of money. For a quick and dirty conversion of pieces of code, I have found the following to work pretty well.

You may have already used Red Gate’s Reflector application (formerly Lutz Roeder’s Reflector), downloadable for free here:

http://www.red-gate.com/products/reflector/

Reflector is typically used for digging into assemblies that you don’t have the source code for and figuring out how they work. However, by using the language dropdown, you can get a pretty decent language converter.

Let’s assume you have a sample written in C#. For this example, I’ll use a piece of code from our upcoming book, Hello! Silverlight 2. As a side note, you won’t have to use a method like this for converting the samples in our book since we will be including all of the samples as both C# and VB.NET inline in the book’s text.

If we select the dll output from a Silverlight project, and then select one of the classes in it, let’s say FishEyeMenuItem in our case, you’ll see the following:

reflector

Then you can click on the Expand Methods link in the right hand pane, and see all of the C# source code for this class:

reflectorcs

Now if you look in the top toolbar, you’ll see a dropdown that says C#. Change that to “Visual Basic” and Expand Methods again and you’ll see something like this:

reflectorvb

Now since this is code for a user control, there is generated code mixed in here, specifically the InitializeComponent method and some generated field definitions corresponding to XAML elements. So if you try to copy and paste this into a VB version of the project you would get duplicate definitions. It’s pretty easy to track those down and remove them though, and the code then should work as-is.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Dec 09 2008, 02:21 by Bill Reiss | Comments (8) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
NewTeeVee Reports: Netflix to Lay Off 50. Blames Silverlight.

So I saw the headline and my heart sank. After news, some accurate and some distorted, showcasing wins of Flash over Silverlight comes this article:

http://newteevee.com/2008/12/08/netflix-to-lay-off-50-blames-silverlight/

The article refers to this announcement on the Netflix blog:

http://blog.netflix.com/2008/12/changes-in-customer-service.html

In the announcement, Steve Swasey from Netflix says the following:

For those of you who watch movies instantly on your PC or Mac, you may have noticed our player is much easier to install and use now with Silverlight. The good news is fewer problems for you. The bad news is that we are now overstaffed with technical specialists in our Customer Service (CS) group.

So last week we announced internally some changes in CS. 50 of our technical specialists will work through December, then be let go in early January after the holidays. 15 of our technical specialists will take new roles in the main CS group.

I hate to see more people getting laid off, but definitely some positive news for Silverlight.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Dec 08 2008, 06:59 by Bill Reiss | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Embedding a F# class library in a Silverlight 2 Application

I’ve been preparing for my F# session at the MSDN Developer Conference in Orlando on December 11 and came across a blog post on creating a Silverlight application using F#. Here is the original post:

http://jyliao.blogspot.com/2008/11/f-and-silverlight-20.html

Unfortunately it was only a description of how to do it, but there wasn’t a sample. In this post, F# was used to do everything. This isn’t really what I was looking for. I wanted to write a C# Silverlight application but call into an F# class library.

Disclaimer: This is a hack and I’m not responsible for what it might do to your system. Also I’m not sure of the licensing of the FSharp.Core.dll but I would guess that you can’t redistribute it, so only use it for testing until a true FSharp.Core.dll is available for Silverlight.

For those who aren’t familiar with F#, it’s a functional or declarative language that compiles into .NET byte code and is becoming popular for banking and scientific applications. You can read more about F# here:

http://msdn.microsoft.com/en-us/fsharp/default.aspx

Compiling F# for Silverlight is a bit tricky right now because a Silverlight version of the runtime hasn’t been released as far as I can tell, and there is no project wizard to create an F# Silverlight project.

After a lot of hacking, I’ve come up with something that will work, and is easy for anyone to start using. What I have created is a Visual Studio project template which creates a C# Silverlight application and also an F# class library.

FSharp.Core.dll is the F# runtime. Since it’s not compiled against the Silverlight runtime, can’t be added to a Silverlight project in Visual Studio, but if the project creation wizard puts it in there it seems to work ok.

The first thing you’ll need to do is install the F# 1.9.6.2 CTP

Then download this project template that I created:

http://www.bluerosegames.com/silverlightfsharpproject.zip

and put it in your Documents\Visual Studio 2008\Templates\ProjectTemplates folder. Once you do this, if you do a “New Project” in Visual Studio, you should see a new template under the “My Templates” section:

fsproj

When you create this app, you’ll get some warnings about trusted imports, etc. If anyone can figure out how to get rid of these, please let me know.

What you’ll have after creating the project is a main Silverlight Application, a web application if you chose to create one, and a F# class library project. The F# class library would typically have a .fsproj extension, but I could only get it working if you use a .csproj extension, so there you go, told you it was a hack.

To get you started with a Hello World type sample app, the Module1.fs in the F# project is created with the following:

 

#light
 
namespace SLFSharpApp16_FSharp
 
type TestClass = class
    new () as this = {}
    member s.Hello() =
        "Hello from F#"
end 
 

This creates a class called TestClass with a method called Hello that returns a string.

Now in the main Silverlight project, the Page.xaml is generated with a TextBlock in it that we will populate with the text from the Hello method:

<UserControl x:Class="SLFSharpApp16.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock x:Name="text" Text="Text from FSharp test will go here"/>
    </Grid>
</UserControl>

and the Page.xaml.cs calls into the F# class library:

using SLFSharpApp16_FSharp;
 
namespace SLFSharpApp16
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            TestClass test = new TestClass();
            text.Text = test.Hello();
        }
    }
}

If you run the solution without any changes after it’s created you should see the following, with the text coming from the F# Hello method:

hellofs

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Dec 07 2008, 13:42 by Bill Reiss | Comments (23) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Thoughts on the MIX 10K challenge

For those that haven’t heard, Microsoft has announced an interesting contest in conjunction with the MIX09 conference in Las Vegas. The way the challenge works is that you need to create a program where the source code is less than 10K bytes (10240 bytes) in Silverlight or WPF XBAP that will run on the web.

Rules and details are here:

http://2009.visitmix.com/MIXtify/TenKGallery.aspx

These types of competitions have been going on pretty much since computers have been around, and in particular, the Demoscene has some great samples of tiny programs doing amazing things.

The prizes are pretty sweet, including a trip to MIX09, $1500 Visa gift cards, and $500 Visa gift cards.

So a few thoughts on how to cram something into 10K.

First of all, forget a lot of what you learned about good programming techniques. Unless you’re ultimately saving space by breaking something into multiple methods or classes, shove everything together.

Make your variables and methods a single character if possible. You can write using longer names and refactor->rename later if it’s easier.

Reduce whitespace. C# can be written as a single line for the entire file.

Make sure to use using statements to avoid having to specify the namespace, but remove any unused using statements from your source files.

Use the built in .Net framework provided classes whenever possible instead of writing your own.

Consider using F# which can often use less characters for the same logic.

For any graphics, determine whether it’s more efficient to represent it as XAML or a bitmap image. Also consider writing code to create the graphics if it’s less characters than the XAML equivalent.

Anyone else have good suggestions to add to this?

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Dec 04 2008, 03:34 by Bill Reiss | Comments (27) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Silverlight Games 101 Blog moved and new content

Just a quick note in case you used to follow the Silverlight Games 101 blog on Silverlight Rocks that we’ve shut down the Community Server based Silverlight Rocks site and now I’m hosting the Silverlight Games 101 blog here:

http://www.bluerosegames.com/silverlight-games-101/

I’ve started updating the old posts to Silverlight 2 RTW and instead of editing the old posts I’m creating new posts that reflect the changes. For those not familiar with Silverlight Games 101, it’s a beginning Silverlight game development blog, and I’m currenty stepping through how to create an Asteroids clone.

You can also subscribe to the RSS Feed here:

http://feeds.feedburner.com/SilverlightGames101

On a related note, the forums that used to be hosted at Silverlight Rocks have been replaced with forums here:

http://forums.bluerosegames.com

These forums include discussions on Silverlight and XNA game development.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 24 2008, 02:31 by Bill Reiss | Comments (0) RSS comment feed |
  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Any decent free Flex development environments out there?

I’m not trolling here, I really want to know. I’d like to do some simple samples on here comparing Flex and Silverlight but I don’t want to do it bad enough to spend $249 on it. I know there is a free trial, but I’d like to compare apples to apples in this case and use a free environment for both.

Any suggestions?

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 18 2008, 14:27 by Bill Reiss | Comments (1) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Scott Guthrie gives a glimpse at Silverlight 3

One of the best places to get some teasers about new functionality coming in Microsoft technologies is Scott Guthrie’s blog. In the unlikely case you aren’t subscribed already, here is what he had to say about Silverlight 3:

Next year we will ship our next major Silverlight release -- Silverlight 3. 

Silverlight 3 will include major media enhancements (including H.264 video support), major graphics improvements (including 3D support and GPU hardware acceleration), as well as major application development improvements (including richer data-binding support and additional controls).  Note these are just a small sampling of the improvements - we have plenty of additional cool features we are going to keep up our sleeves a little longer. ;-)

And here’s the entire post:

http://weblogs.asp.net/scottgu/archive/2008/11/16/update-on-silverlight-2-and-a-glimpse-of-silverlight-3.aspx

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 17 2008, 00:49 by Bill Reiss | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
MSDN DevCon Orlando After-Event Social on December 11

These days for me, the best part of any conference or event is who I get to meet. One of the best places for this are the socials after the event or in the evenings. Joe Healy has announced (you do read his blog don’t you?) that he is holding a raffle for a limited number of spots to a social event after the MDC in Orlando on December 11. Meet the speakers, Microsoft representatives, and influentials.

Details are on Joe’s blog here:

http://www.devfish.net//FullBlogItemView.aspx?BlogID=613

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 10 2008, 01:57 by Bill Reiss | Comments (2) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
I'm speaking at the MSDN Developer Conference in Orlando

The MSDN Developer Conference (MDC) is coming to a city near you. There are 11 cities hosting an MDC event:

http://www.msdndevcon.com/Pages/start.aspx

The MDC is like a "Best of PDC” event, and will have some great content. I’m honored to be included in the list of presenters for MDC Orlando on December 11. It’s $99 to attend, a lot cheaper than PDC and you don’t have to go all of the way to Los Angeles. Hope to see you there.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 09 2008, 14:39 by Bill Reiss | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Silverlight Streaming updated to Silverlight 2 RTW (Finally)

Well I don’t know what took them so long, but now you can load Silverlight 2 RTW apps from Silverlight Streaming. Here is my Stack Attack game running there:

http://silverlight.services.live.com/invoke/66997/StackAttack/iframe.html

I’ll update my “dogs” photomosaic DeepZoom soon.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 01 2008, 16:48 by Bill Reiss | Comments (2) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Creating a Mesh-enabled Silverlight web app is easy

So with the tokens I acquired at PDC to try out the Live Services framework, I was able to create a Mesh-enabled Silverlight application. It still needs some work, such as storing high scores in the Mesh, but you can see Dr. Popper running on the desktop in this screenshot as a Mesh-enabled app:

drpoppermesh

Pretty cool, and it only took a couple of hours, it only took that long because I was having a brain malfunction and forgot that I needed the tech preview version of Mesh running on my desktop instead of the release version. Pretty exciting stuff. I hope that it doesn’t take too long to open up the tech preview to more people than just those at PDC.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 01 2008, 15:39 by Bill Reiss | Comments (2) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Offline Apps in Silverlight?

I’ve just returned from PDC and I’m starting to recover, what a huge amount of information in a few days. I also met some great people, from Microsoft and others. With many of the sessions available online, it really has turned the need to go to conferences into more for the social aspects and less for seeing the sessions. I’ll be catching up on sessions I missed that were going at the same time for days.

The most interesting announcement to me was that you will be able to write mesh enabled web applications that run “outside the browser” and can run in an offline mode. These can be written in Silverlight or in other web technologies. You can think of this as similar to Adobe’s AIR platform.

So how does it work? It’s actually pretty clever. I’ll do my best to explain how I think it works bet I may get some of it slightly wrong technically.

When you install the Live Mesh client on your machine, you get the Live Mesh runtime and you also get a process that you can communicate with locally that proxies your Mesh requests to the Live Mesh Server. This is the process that the Mesh enabled application talks to to get the XAP file and any data it needs. This process handles HTTP requests just like the server in the cloud does. By talking to a local server, the application can work without a connection to the internet.

Now for the outside the browser part. It’s technically not outside the browser since the applications run in a process that hosts a browser control which I would guess is the Internet Explorer control on Windows, and would probably be a Webkit based control on Mac.

I have some ideas already about how to use this new technology and I think it will make for some really interesting possibilities. Think of it as social networks for applications.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Nov 01 2008, 12:08 by Bill Reiss | Comments (14) RSS comment feed |
  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Viewbox in the Silverlight Toolkit

It may be one of the simpler controls in the new Silverlight Toolkit http://www.codeplex.com/silverlight but it’s one that I have to keep writing myself so I’m happy to see the Viewbox in the Silverlight Toolkit. So what’s a Viewbox? The Viewbox has been available in WPF, and it takes one child element and automatically stretches or scales it to fit the size of the Viewbox.

Consider the following Page.xaml:

<UserControl x:Class="ViewboxSample.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:scp="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls">
    <Grid x:Name="LayoutRoot" Background="Black">
        <scp:Viewbox Stretch="Uniform"> 
            <Image Source="dog.jpg"/>
        </scp:Viewbox> 
    </Grid>
</UserControl>

The Viewbox is set to Stretch=”Uniform”, so the image is scaled to fit the viewbox, taking as much space as possible while still showing the entire image and preserving the aspect ratio.

uniform

This isn’t super interesting since a grid cell can do this. However, the Viewbox has some other options. If you use UniformToFill for Stretch, the aspect ratio is still preserved, but there is no letterboxing. This is sometimes called “Zoom mode” on an HDTV widescreen when displating standard definition content:

<Grid x:Name="LayoutRoot" Background="Black">
    <scp:Viewbox Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center"> 
        <Image Source="dog.jpg"/>
    </scp:Viewbox> 
</Grid>

This gives the following effect:

uniformtofill

You can also use Stretch=”Fill”, which fills the entire space but does not preserve the aspect ratio, so things can get stretched.

fill

Now where this gets more interesting is if the child of the Viewbox is a Panel of some kind. Let’s wrap the image in a Grid and add a TextBlock as well.

<Grid x:Name="LayoutRoot" Background="Black">
    <scp:Viewbox Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"> 
        <Grid Width="640" Height="480">
            <Image Source="dog.jpg"/>
            <TextBlock Text="Our Puppy" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30" Foreground="White"/>
        </Grid>
    </scp:Viewbox> 
</Grid>

This produces the following result:

gridwithscaling

This key point here is to notice that the text scales along with the image. So if you want to scale your entire application to any size, for example to go into full screen mode, you can use the Viewbox to do this easily.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Oct 28 2008, 08:49 by Bill Reiss | Comments (12) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Silverlight Toolkit available for download

This morning, Microsoft has made the Silverlight Toolkit available. Shawn Burke has posted details here:

http://blogs.msdn.com/sburke/default.aspx

Lots of great new controls and theme capabilities available.

You can download the Toolkit here:

http://www.codeplex.com/Silverlight/Release/ProjectReleases.aspx?ReleaseId=18804

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Oct 28 2008, 08:00 by Bill Reiss | Comments (12) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: