Rants

<<  <  4  5  6  7  8  9  10  11  12  13  14  +  >  >>  (Total Pages: 91/Total Results: 910)

New Silverlight Tour Stops!

Silverlight Logo

With the success of our first two Silverlight 2 Workshops, the Silverlight Tour is expanding to three new cities and more stops.  The new cities are:

  • New York, NY
  • Denver, CO
  • San Diego, CA

We've also expanded our schedule out to the end of the year.  We'll be returning to Seattle and Dallas. Don't miss out on three days of Silverlight 2 training in a city near you.

Reading Silverlight Embedded XAML

Silverlight Logo

I was talking with Walt Ritscher (of VB MVP fame) recently and he noted that he was trying to find a good way to grab XAML out of the assemblies in Silverlight 2. While Walt got a great answer from his brethren at Wintellect, I wanted to point out a quick way of reaching into the project to get the XAML

One thing I noted was that I knew that the Silverlight 2 template reached into the assmebly to get the XAML at runtime so that code had to be there.  And it is there.  Its there in the 'codegen' class for every XAML based class (e.g. Page.xaml and other user controls). To get there easily, go to your Page.xaml and find the InitializeComponent call and press F12 to open that method.  This will open up the Page.g.xaml (the generated partial class). This leads us to this code:

public void InitializeComponent()
{
  if (_contentLoaded)
  {
    return;
  }
  _contentLoaded = true;
  System.Windows.Application.LoadComponent(this,
    new System.Uri("/SeeMyXaml;component/Page.xaml", 
                   System.UriKind.Relative));

  this.LayoutRoot = ((Grid)(this.FindName("LayoutRoot")));
  this.theXaml = ((TextBlock)(this.FindName("theXaml")));
}

Note the LoadComponent call.  It specifies a Uri to load the XAML right there is our project all along! 

So what can we do with it?  I've crufted up a simple project (link provided above) that reads the XAML with a XDocument class then spits it out (with formatting but not coloring) in a TextBlock.  The code is dead simple:

// You may need to add System.Xml.Linq reference to get 
// the XDocument class
XDocument doc = XDocument.Load("/SeeMyXaml;component/Page.xaml");
theXaml.Text = doc.ToString(SaveOptions.None);

You should notice that we're using that same path syntax to get the Page.xaml from the embedded resource. Simple, huh?

Silverlight Policy Snippet and Intellisense

Silverlight Logo

Over at Tim Heuer's blog, he has a great article and download to get a new Snippet to create Silverlight Policy files.  If you are doing any Silverlight 2 work with Web Services, its a must install AFAIAC.

If you don't know, Tim recently joined the Silverlight Evangelism group (with Laurence Moroney, Adam Kinney, Jesse Liberty, et al.).  If you're interested in Silverlight, this is a blog you should definitely subscribe to.

Meetup in Seattle

Silverlight Logo

I decided to have a quick meet-up of some of my Twitter contacts in Seattle this week.  I figured I should open it to anyone else who wants to show up.  Follow the GeekDinner link above to RSVP so I can tell the bar to make room.  Let me know if you have any questions about the dinner!

Note: GeekDinners isn't perfect yet but after I get back from Seattle I will be doing some improvements to the site to make it a bit easier to use. If you want to volunteer let me know.

HtmlWindow.Navigate and enableHtmlAccess

Silverlight Logo

Adam Kinney (of Silverlight Evangelism fame) was finding some odd behavior with his new (and cool) Silverlight Powered XBox Gamercard. Of interest was the Gamertag link on the Gamercard. When you use it on his site, it works like a dream but once you put the Gamercard on a separate site the link would cause the Silvelright app to just disappear instead of navigating to XBox.com.  

One note, Adam figured it out...not me.

So what is going on.  Adam noticed that it worked on his site unless the subdomain was different (it was working on www.adamkinney.com but not adamkinney.com). It turned out that the issue was that enableHtmlAccess was not enabled.  This is a great case where Adam should have used HtmlPage.IsEnabled.  In case you're not aware, the HtmlPage.IsEnabled returns true if the Silverlight application has the right to deal with the HTML page.  But how is this determined?

There are three ways to host Silverlight today:

  • <object> tag
  • Silverlight.js
  • <asp:Silverlight /> control for use on ASP.NET 3.5 AJAX pages

For Adam's needs he was using the <object> tag so that people could drop it on their blog and it would just work. By default enableHtmlAccess is false when using the <object> tag hosting method. So the fix for Adam's problem was to add this parameter to the object tag.  Go look at the Silverlight Gamertag toy if you want to see how that works.

The real issue here is consistency.  I assume Adam has worked with Silverlight like I have.  Lots of small to medium sized examples.  Examples are cool but generally that means we've been creating Silverlight content but using the most simple method for hosting our examples.  This means the asp:Silverlight control. This wasn't obvious to either of us though because in both the Silverlight.js and <asp:Silverlight /> hosting method the enableHtmlAccess defaults to true...which is opposite of the <object> method.

So the lesson learned here is to use HtmlPage.IsEnabled to test to see if your particular host allows access to the HTML of the page (including support for HtmlWindow.Navigate).

HTH

Adam Kinney has a new SIlverlight-based XBox Gamercard

Silverlight Logo

Adam Kinney has created a new Silverlight 2 Application to show off your XBox Gamercard on your site.  I like his design and it is not static so it shows what you're doing at any specific time.  What do you think of mine:

Get Microsoft Silverlight

Do you like?

Silverlight Compatibility Confusion...

Silverlight Logo

While reading through the Silverlight Runtime system requirements, I found two important (but under reported) limitations:

While I understand the Windows 2000 limitation.  Back porting the Silverlight 1.0 makes sense to me. But I hoped some of my Apple-savy readers (if I haven't pushed them all away) could tell me whether the PowerPC story matters.  Will non-support for Silverlight 2 matter to PowerPC Mac OSX users?

 

Silverlight 2 Bugs and Issues

Silverlight Logo

As I've been neck-deep in Silverlight 2 for a couple of months now I noticed that there are some bugs/inconsistencies that aren't necessarily known to everyone. Here's a list of some of the issues (with workarounds if possible):

Custom Control Data Binding

If you are writing User/Custom Controls that want to be used in data binding (i.e. DataTemplate), you must use the assembly name in the namespace declaration, even if it is in the main assembly:

Bad:
xmlns:my="clr-namespace:MyAssembly.Controls"
Good:
xmlns:my="clr-namespace:MyAssembly.Controls;assembly=MyAssembly"

This is a known bug that will be fixed in future builds.


Uri Issues

In Silverlight 2 (in contrast to previous versions) the assets are packaged up in a .xap file.  This .xap file is simply a ZIP file that contains the assemblies and other assets.  In this file you can have images, fonts and other assets required.  This new facility has made Uri's a bit confusing.  When you specify a relative Uri in your Silverlight 2 project it may mean inside the .xap file or it may mean from the server. 

The key is that relative Uri's will first look in the .xap file then look on the server but this isn't universal.  For example if you have a foo.jpg in the root of your .xap file and specify this Image tag, it will find it in the .xap file:

<Image Source="foo.jpg" />
 

If the foo.jpg doesn't exist in the .xap, Silverlight 2 will look at the server for the file (most of the time)...but where is it looking?  Unlike what you might expect, it actually looks on the file server relative to the ClientBin directory (where the .xap file is loaded from).  If you want to have an image file loaded from the /image folder of the web server you would specify:

<Image Source="../images/foo.jpg" />
 

This works because it is relative to the ClientBin directory.  If you specify "/images/foo.jpg" it won't look on the server.  This is the bug.  Using a full path to the server fixes this but that is fragile (you need to change it when you deploy an application).

This is especially an issue with MediaElement as it doesn't seem to work at all with relative paths.  Interestingly if you look at the Uri usage with Reflector, the Source property in the MediaElement strip off the Uri and just send it the plain string (again, this is what I consider a bug). So if you're using a MediaElement, use non-relative paths for the Source.

In general I have found different/buggy behavior with different controls so if you are having trouble with Uri's, go to non-relative Uri's (e.g. full paths).


Using the Silverlight Control

 If you want to use the ASP.NET Silverlight Control it requires ASP.NET AJAX 3.5.  It requires a ScriptManager on the page and only works with the 3.5 version of AJAX. This means that if you are not using AJAX 3.5 you will need to use one of the other methods:

I tend to like the Silverlight.js for deployed projects anyway because of the additional functionality of Silverlight.isInstalled and other small features.  If you used Silverlight 1.0 you'll  already be familiar with Silverlight.js.  The version that ships with Silverlight 2 has been updated to support Silvelright 2 deployment.


ImageBrush Can't Be Data Bound

This is a small but pesky bug that if you try to use data binding with the Image brush it just fails (or locks up the browser).  So if you want to set the ImageBrush, you'll need to wrap a UserControl and data bind a DependencyProperty that will set the ImageBrush manually.  Not hard but just a workaround.


LINQ Projections or Anonymous Types Fail on Data Binding

If you are using LINQ to do projections or using Anonymous types, data binding gets confused and tends to lock up the browser.  For example:

var qry = from x in customers
          select new
          {
            Name = x.CustomerName,
            Phone = x.ContactPhone
          };

theList.ItemsSource = qry.ToList();

The alternative is to just select the entire object (or use static types instead of anonymous types).


Popup.DataContext Doesn't Work

If you are using the cool Popup element and you want to use Data Binding to fill in data, the DataContext of the Popup fails to propogate its container.  Therefore you need to manually set the first child's DataContext instead:

<Popup DataContext="{Binding}" /> <!-- Doesn't Work -->


That's all for the issues that I am working around these days.  If you have more, feel free to drop them in the comments!

Not Sure the Copy Bug in Gone in Vista SP1

I am copying a video file across my wireless network (though this particular machine is kinda flaky, so it might not be Vista's fault) but I thought this was funny:

 

Atlanta Code Camp 2008 Presentation Slides and Demos

Silverlight Logo

As promised here are the slides and demo's from my talks at the Atlanta Code Camp yesterday. It was a great time and I got to see a lot of attendees and speakers who I haven't seen in a while. 

My big embarrassment moment was at the speaker's dinner when I saw David Silverlight and completely forgot who he was (i've met him a number of times).  When I heard he'd just flown in from Florida, I asked him, "Did you fly in with David Silverlight?".  He promptly replied, "In a sense, yes..."  I was so red faced. 

On to the slides and demos:

Enjoy!