SolidColorBrush not reusable

In Silverlight I have just discovered by trail by fire the you should not reuse Brushes. Seems really odd coming from a Win32 GDI background to not use the same brush but the following code throws an exception on the second assignment.

SolidColorBrush  green = new SolidColorBrush();
green.Color = Colors.Green;
Run ra = new Run();
Run rb = new Run();

ra.Text = "Run A";
rb.Text = "Run B";
ra.Foreground = green;
rb.Foreground = green;

With this

Value does not fall within the expected range.

at MS.Internal.XcpImports.SetValue[T](IntPtr oPtr, UInt32 iPropertyId, T obj)
at System.Windows.DependencyObject.SetValue[T](DependencyProperty property, T obj
at System.Windows.Documents.Inline.set_Foreground(Brush value)

Hmm, what means lots to me…

So I changed how I was wiring it all up and found a better SolidColorBrush constructor as well. So it should be done like

Run ra = new Run();Run rb = new Run();

ra.Text = "Run A";
rb.Text = "Run B";

ra.Foreground = new SolidColorBrush(Colors.Green);
rb.Foreground = new SolidColorBrush(Colors.Green);

Which feels wrong, but works. I’m guess as Silverlight is not GDI based there are no window handles the manage, so it works better this way.

Visual Studio 2008 Beta 2 is out…

From Darryl I learnt Visual Studio 2008 Beta 2 is out. Damn it, I had only just gotten Beta 1 installed and working how I liked in my VPC at work.

Well I’m excited really about the new version, but more annoyed at all the system updates that wasted so much time this week, when all I want to do was experiment with Silverlight.

Now I’ve just got to not restart my dev machine over the next ~7 hours while it comes down.

I was wondering about Silverlight, but reading Soma’s details Silverlight 1.0 RC is due any day now also. Woot!

It’s All About Silverlight

Today’s .Net User Group meeting was “It’s All About Silverlight” was presented by Kelly Cliffe. It was all about Silverlight, and although Kelly mentioned it was his first public speaking since high school he gave a good talk.

The talk was 101 with meat, so maybe a 201 level with some stories from the battle field (~301 level tit bits).

At the end there were Mix 07 DVDs being handed out and I got Discs 1, 3, 7. So fueled up with Silverlight Cool-Aid I headed home to installed Orcas Beta 1 on my PC. The only thing missing from the DVD set was the “Microsoft Silverlight Tools Alpha for Visual Studio codename “Orcas” Beta 1” and once that was all installed it just worked!

I had previously download a Digger(Boulderdash) Silverlight example that I found on Lutz Roeder’s site. It was a VS2005 project so I had fun coping it into a Orcas project and getting it working. Was quite useful seeing how the parts of the namespace/project/output names are used in the xaml etc (ie this was where my pain points were).  Of note is that my version only runs in IE yet Lutz’s current Digger runs fine in FireFox.

So now I have some working code, I need to think what I want to build. I’m not sure but it’s a heck of a lot more accessible than Flash has appeared to be. That might be the tipping point.