March 2009 Archives

You were a frakkin good show

So say we all!

Battlestar Galactica coming to a close, but Caprica remains inbound.

A few weeks ago, for the first time in my life, I watched a TV episode twice. Back to back, with no break in be­tween. Blood on the Scales, for me, was pure gold. The story was in­cred­i­ble, es­pe­cially if you got the chance to see the we­bisodes that sup­plied im­por­tant con­text for it. The act­ing was top-notch. Alessan­dro Ju­liani in par­tic­u­lar, who has had a rel­a­tively small amount of screen time be­fore now, re­ally stepped up to de­liver a won­der­ful mov­ing per­for­mance. The music—oh my sweet god the music. Any­one who knows me well will know my love for the BSG sound­tracks, but the music in this par­tic­u­lar episode spoke to me on such a pro­found level that I lit­er­ally missed di­a­log at points and had to rewind to hear it again. I will be shocked, pleas­antly, if I ever watch an­other episode of any other TV show that af­fects me like this one.

This Fri­day be­gins the final count­down for Bat­tlestar. It will be the first in a three episode arc to end the se­ries. On one hand I am sad to see it go. I will miss not just watch­ing it, but hop­ping on­line af­ter­ward to read Bear Mc­Creary’s en­thralling be­hind-the-scenes sum­mary of the score. But on the other hand, I would rather see it get the strong fin­ish it de­serves than see it be­come the prover­bial Old Yeller like Star­gate: SG-1 did.

But Caprica will be start­ing early next year, so maybe all is not lost. I worry about them milk­ing the mythos to death in it, but these guys trans­formed a corny 70s show into some­thing amaz­ing, so I have a lot of hope. Ear­lier this month, Bear gave an early pre­view per­for­mance of the music of Caprica.

Alex Filo has the right idea, UniformWrapPanel

WPF’s Wrap­Panel is miss­ing a key fea­ture: the abil­ity to cre­ate ver­ti­cal columns, but still fill the max­i­mum amount of width avail­able. One less an­noy­ance in WPF, thanks to Alex Filo’s Uni­formWrap­Panel.

Qt 4.5 released, still using three year old GCC

Qt 4.5 is out, along with Qt Cre­ator. It’s still using GCC 3.4.5, from a Jan­u­ary 2006 code­base. Sigh.

Databinding TextBlocks with XAML

I’ve be­come frus­trated lately with try­ing to data­bind a list of strings to a textblock. Ie, if I have:

string[] mytext = new string[] { "a", "b", "c" };

And I want the ef­fec­tive end re­sult to be:

<TextBlock>a, b, c</TextBlock>

Or maybe I want some­thing more com­plex like hy­per­links:

<TextBlock>
   <Hyperlink>a</Hyperlink>,
   <Hyperlink>b</Hyperlink>,
   <Hyperlink>c</Hyperlink>
</TextBlock>

Ba­si­cally what I’m look­ing for is a Item­sCon­trol that works on TextBlocks (or Spans, etc.), with a Sep­a­ra­tor tem­plate to in­sert those “, ” in be­tween the items.

Your first in­stinct might be to use a Stack­Panel in­stead, but Stack­Panel wasn’t made for dis­play­ing text. It might fool you ini­tially, but you quickly no­tice it doesn’t be­have any­thing like text: there’s no proper kern­ing, RTL, wrap­ping, or any­thing else the text classes were made to sup­port.

I’m pretty sur­prised that WPF doesn’t have any­thing like this, as it seems like dis­play­ing lists as text would be a com­mon enough thing for any app. Un­for­tu­nately I’m still not well versed enough in WPF to cre­ate such a cus­tom con­trol for my­self, and haven’t had a whole lot of time to in­ves­ti­gate it.

Using HSL colors in WPF

One thing that has al­ways ir­ri­tated me about WPF is you’re still stuck spec­i­fy­ing col­ors in RGB. HSL just feels so much more nat­ural from a de­sign stand­point. Well, we’re not com­pletely out of luck—we’ve got markup ex­ten­sions.

So I cre­ated my own Hsl­Color and HslBrush ex­ten­sions which are fairly sim­ple to use:

<Window xmlns:e="clr-namespace:WpfExtensions"
        Background="{e:HslBrush H=300,S=50,L=75,A=80}"/>

Hue is spec­i­fied in de­grees from 0 to 360, while Sat­u­ra­tion, Light­ness, and Alpha are from 0 to 100. The pa­ra­me­ters are all dou­bles and it con­verts to scRGB be­hind the scenes, which means you ac­tu­ally get a much higher color pre­ci­sion than if you had just used the equiv­a­lent RGB hex. With Win­dows 7 hav­ing na­tive sup­port for scRGB, this will fu­ture-proof your ap­pli­ca­tion to make good use of up­com­ing mon­i­tors with Deep Color sup­port.