Archive for December, 2007

Design Quiz

Wednesday, December 19th, 2007

Think you’re a designer?  Take the quiz and find out for sure.  I missed three.  I felt good about that and still stand by one of my "wrong" answers.

Dr. WPF’s Snippet Emporium

Wednesday, December 19th, 2007

Okay, so it’s not an emporium because I think that technically an emporium should have something for sell and these are FREE.  But they’re definitely the best VS snippets for WPF that I’ve come across (although feel free to comment if you have others that you like as well).  Oh, and while you’re at it, this is a great blog.  The elusive Dr. WPF has a real flare for breaking complex concepts down into really understandable pieces.  So go for the snippets and stay for the ItemsControl quiz (and other great content).

RandomNumber MarkupExtension

Tuesday, December 18th, 2007

This is a really simple example of a custom MarkupExtension.  It generates a random number and then returns it as either an integer, string or double.  It turns out that its only semi-useful, though, because it doesn’t work well inside of a template.  This really illustrates how MarkupExtensions get used…it does generate a random number, but it only does so once.  So every time you use the template it gets the same value (not especially random).  This is because MarkupExtensions get evaluated by the parser at parse time.  Since the XAML in the template is only parsed once, you only get one random number.

This worked for my scenario because it was outside of a template.  I was just generating content and wanted to test some random data.  Inside of a template, you could write a ValueConverter (to use in conjunction with a binding) to accomplish the same thing.  If someone writes that, let me know…

One other thing that’s worth noting in the code below is that the Random is a static.  That’s good practice because for plenty of reasons, but one interesting thing side effect of letting it be an instance variable was that things got way less random.  I think that the Random class must seed itself with clock data when it gets instantiated.  Apparently these get instantiated faster than the granularity of the clock data so the random numbers end up coming in batches that all have the same value.

Here’s a usage example of the MarkupExtension version:

<Button>
  <Button.RenderTransform>
    <RotateTransform
       Angle="{l:RandomNumber Min=0, Max=360}" />
  </Button.RenderTransform>
</Button>

And here’s the class itself:

public class RandomNumber : MarkupExtension
{
    private static Random R = new Random();

    public override object ProvideValue(IServiceProvider sp)
    {
        double r = R.NextDouble();
        double value = Max - (r * (Max-Min));

        if (AsString)
        {
            if (IsInteger) value = (int)value;
            return value.ToString();
        }
        else
        {
            if (IsInteger)
            {
                return (int)value;
            }

            return value;
        }
    }

    private bool _AsString = false;
    public bool AsString
    {
        get { return _AsString; }
        set { _AsString = value; }
    }

    private bool _IsInteger = false;
    public bool IsInteger
    {
        get { return _IsInteger; }
        set { _IsInteger = value; }
    }

    private double _Max = 1;
    public double Max
    {
        get { return _Max; }
        set { _Max = value; }
    }

    private double _Min = 1;
    public double Min
    {
        get { return _Min; }
        set { _Min = value; }
    }
}

Gift Ideas

Friday, December 7th, 2007

Looking for that rare gift that says both "nerd" and "art?"  It’s not an easy find, but in my holiday shopping quests so far I’ve come across some items that I wish someone would get for me.  So, in the spirit of sharing:

image1. The Gakken Cup Phonograph Kit in Edison-style "allows you to record your voice through a cup onto another one."  Yeah, this one is low tech but, at least according the manufacturer, it’s not only an "ultra fun experiment," but also an "absolute neat gift idea."  I think they mean absolute in the same way one says "absolute zero."  In other words, the neatness of all other gifts will be defined relative to this one so if neat is your goal, look no further.

 

 

 

Visualizing Data2. Ben Fry’s (upcoming) new book Visualizing Data.  If the recipient of your gift isn’t familiar with Ben, then just the introduction by itself is a high quality gift.  I saw him speak about Processing at Flash in the Can in 2005 and I was blown away.  His is the best version of data + art that I know of.  You can see a draft of the first six chapters here.  This is a great one for the WPF enthusiast because, as we all know, WPF is all about the data.

 

 

3. A poster by Jason Munn, band poster designer extraordinaire and proprietor of thesmallstakes.com.  His poster shop features all original, limited edtion posters that are not only amazingly cool but less expensive than you expect (only $25 a pop!).  He does the design and silk-screening himself.  I have 4 hanging in my office right now (those pictured below) and secretly hope to get one or two more for Christmas.  The cool ones sell out quickly, so don’t hesitate.  You can read interviews with Jason here and here and even see the sketches that led to the posters.

image

 

image4. Allright, If you’re really on a budget this year, go for the paper bird.  Not only can you design your own (a personalized paper bird can go a long way), but your giftee could put his or her design and/or paper cutting skills to work as well and craft his or her own.  This, by the way, is a gift that targets a broad range of ages and has already been calendared in our home as a holiday project to be shared with my three year old.

 

5. Another option for the budget aware gift giver: Free fonts.  That link is to Smashing Magazine’s list of "excellent" and free fonts, and many (even most) really are excellent.  This is another great find for your friend or family member who dabbles in either WPF or Silverlight since both have great support for custom fonts.  It would also be a great gift for your school teacher mom (like my mom!)

image

Okay, so there’s a chance that even after going through that extensive list (of five items, two of which are free), you still haven’t found the right match for your giftee.  If that’s the case, do not fret.  Two other excellent (and much more extensive) lists which may fit the bill can be found here and here.  Even if mine didn’t, one of those should meet your nerd+art needs.  In the meantime, best of luck in your holiday pursuits.