Category: <span>WPF</span>

This entry is part 3 of 11 in the series Mazes For Programmers

Part 3 in my ongoing series of how I implemented the code from Mazes For Programmers by Jamis Buck in C#.

The author rendered the mazes in graphical form using a Ruby library that allows you to create PNG images. This requires you to run the code, then open the saved image, then remember to close it before running the code again, otherwise you get a “File access denied” error, all of which seemed like hard work. As I work with WPF on a day-to-day basis, I decided to use that to render my mazes, as it was quicker and easier.

This post shows how I did it.

We have found a problem whereby when a window loads, some of the buttons are disabled. Clicking anywhere on the window (even on the title bar) enables the button, but this doesn’t give a good user experience. Thankfully the fix is simple. You need to find a place in the view model code where all the data has loaded, all events have been raised, and all INC properties have been set. Then you add the following lines… That will fix the issue. Ideally you would do this in the base view model, but this requires having somewhere in there where you know all data has been loaded. If you have that, then consider yourself amongst the blessed

When laying out controls on a window or user control, it is common to end up with wads of XAML that looks like this: Before you even start adding in the controls, you have quite a lot of XAML just for laying out the grid itself. Enter stage left, the GridHelper class (round of applause please). With the addition of the appropriate line to the namespace section of your window or control (depending where you save the GridHelper class): …you can reduce the XAML spaghetti above to the rather more succint: The row or column definitions are now reduced to a comma-delimited list of heights or widths. These can be absolute or star values, and can take an optional minimum value (specified after the colon). Grid splitters Grid splitters are a common feature in complex layouts, and the GridHelper class allows you to add them without writing extra XAML. All…

I was having some trouble with WPF data binding yesterday, where the binding looked correct, but the data wasn’t being shown. It turned out that I had forgotten an .Include() on the original query (this data is being sent across the wire through a WCF service, so I can’t use lazy loading), but along the way, I discovered a really useful blog post on how to debug WPF data binding.