A Simple Word Puzzle

A few weeks back my young son showed me some work that he’d been doing at school – constructing a simple word puzzle by hiding a few known words within a grid of letters. His approach to this was very simplistic – but got me thinking that writing an application to do the same would be trivial and thus something that could keep me busy on the bus trips to and from work.

One night to get started and then a few bus trips later and I’ve got the following:

Word Puzzle 1

The puzzle board itself is actually two ItemsControls layered on top of each other. The lower control has its items laid out using a UniformGrid and each item represents a letter tile. The topmost control superimposes the “solved” words on top of the lower grid. I originally tried doing this just be altering the style of the individual tiles – but this didn’t achieve the effect I was after and got overly complex when a single letter was used by multiple words.

            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                <ItemsControl x:Name="letterItemsControl"
 ItemsSource="{Binding LetterStream}"
                            <UniformGrid Rows="{Binding Height}" Columns="{Binding Width}"/>
                <ItemsControl x:Name="wordItemsControl" ItemsSource="{Binding Words}"
                              ItemTemplate="{StaticResource WordSelection}">

Of course it was pointed out to me that having each letter tile rendered as a set of controls wouldn’t scale well at all. Sure enough, even at 20×20 things start to slow down. Rendering a grid at 100×100 is painfully slow – although to be fare you can’t read the letter tiles at that size either – and it wouldn’t be much fun looking for words on a 10000 letter grid. Whilst a better implementation probably lies down the path of creating a BoardControl that renders all the tiles as one geometry group, I just liked the idea of being able to easily apply styles to the letter tiles, word selection etc.

As it stands this isn’t really finished – but its probably as close as I’ll get. I showed it to my son – he was bored of it after about 30 seconds .

I’ve posted an XBAP version here.

IDataErrorInfo – is there really any point?

When looking into data validation systems that focus around WinForms and WPF technologies the IDataErrorInfo interface is a common focus. Personally I’ve never been satisfied with this interface. Not only does it appear to have some very poorly named members, it just doesn’t seem anywhere near functional enough. Don’t get me wrong – its a great concept – it just seems to be a super-lightweight example.

From MetaData on IDataErrorInfo:

   // Summary:
//     Provides the functionality to offer custom error information that a user
//     interface can bind to.
    public interface
// Summary:
//     Gets an error message indicating what is wrong with this object.
// Returns:
//     An error message indicating what is wrong with this object. The default is
//     an empty string ("&quot.
        string Error { get; }

       // Summary:
//     Gets the error message for the property with the given name.
// Parameters:
//   columnName:
//     The name of the property whose error message to get.
// Returns:
//     The error message for the property. The default is an empty string ("&quot.
        string this[string columnName] { get; }


So if I have a business object, Contact, that implements IDataErrorInfo then to get a description of the validation state for a particular property we use myContact[propertyName]. That really doesn’t seem very intuitive, surely that should be a method call, e.g. myContact.GetPropertyValidationState(propertyName)? Of course because all the return results are strings rather than object there’s no clean path for extensibility here either.

Does anyone really use this interface for anything other that quick data-binding sample applications? Really – I’d love to know.

Paul’s latest foray into a WPF Validation framework got me started on this. Though to be fair his draft framework has clear extensibility points for plugging in a much richer business object validation interface.