Silverlight 3; Building a navigation tree from static and dynamic data

The problem

Build a navigation tree that allows users to navigate to specific static pages, from static entries in the menus, and to pages that are built dynamically based on selections from the menu.

The Solution in a picture

The solution in code

Build the static menu selections in xaml, being sure to name each of the major headings with “Tag” entries;

<Grid x:Name="LayoutRoot">

<controls:TreeView x:Name="treeview"
BorderThickness="0"
Margin="0"
[...]

Silverlight 3 – Binding POCO objects to XAML

Obvious, really, but I spent ages chasing down how to bind some kind of POCO to a XAML display;

<Grid x:Name="LayoutRoot">

<Grid.RowDefinitions>
<RowDefinition Height="300" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
[...]

Silverlight 3 – handling exceptions in page views

How do you handle the situation where your new Silverlight page needs to shout a warning or error, and then die? No idea, but this is how I do it…

Originally, I was quite scared of my Silverlight pages throwing an exception and then I realised that this was just another object and if we throw an exception, hopefully let the user know, and bail out, then that’s fine.

So the pattern I am now working with is this;

Constructor – set up the load operations
Page_Loaded events – bind the XAML objects to the retrieved data

On any error; display a meaningful message, in a semi-modal window
Navigate back to a safe place (e.g. /home)

What do I mean by “semi-modal”? Well, from the user’s perspective, it [...]

Silverlight 3 Navigation – navigating from a UserControl

I’ve been toying with Silverlight over the last couple of weeks and, I have to say, it’s much more complete than ASP.Net ever was (**). Lots of new paradigms to get my head around, of course, but overall it’s a very complete solution for an RIA.

Anyway, to the point of this posting; the new (in Silverlight 3.0) Navigation Framework is great; it allows you to present a common interface and have new pages display in a know part of the browser window, supports browser back/forward, and URL rewrites. See here for more information.

If you are inside a page that is controlled by the framework, then you are able to call on the NavigationService.Navigate method to divert control to a new XAML [...]

Iterating through a bunch of folders and files

So you want to start at a top level folder, and then process all the folders beneath… Maybe you really do want to look at every file (maybe count the total size of the folder), maybe you want to process all the XML files there. The most obvious route is to recursively search through each folder;

static void Main(string[] args)
{
string startFolder = @"C:\temp";

List<string> contents = new List<string>();
foreach (string dir in [...]

Validating XML Files against XSD Schemas (especially for files that don’t reference the schema)

Wow, XML is a pig, isn’t it? Don’t get me wrong; it does everything I need it to do in describing multi-faceted data, but it’s a pretty steep learning curve.

At first, I used XPath and a lot of coded validation. Then I finally invested time in learning XML Schemas (XSDs) and that helped a lot because I could validate the entire document and, only when I knew it was valid, start pulling data out of it. At around the same time, I stumbled upon LINQ to XML and this shortened the code substantially.  Now, all I had to do was validate the document against the XSD and, if it passed, get to decoding it via LINQ and we’re done and dusted [...]

FileTreeView – a SequioaView-like Application

I've long been a huge fan of the SequoiaView application released by Technische Universiteit Eindhoven, which displays disk utilization in a beautiful squarified cushion treemap format. This was released in 2002 and does a great job of showing exactly what's eating the space on your disk, but it has one major drawback; if you point it at a 2TB volume with a million files, but you only want to see what's taking the space in a small corner of the disk, it reads the entire volume before displaying what you originally asked it to. So, I decided to write a C# alternative to SequoiaView, partly to help us find the big files in specific folders really quickly, and partly just as [...]

Horrible error running against a 32bit .Net Library from a 64bit application

So, this is my first new dev project on my shiny new Windows 7 64bit machine (having come from a 32bit Vista box). As it happens, I want to use the Microsoft Data Visualization Components, which are only available as a set of 32bit DLLs compiled sometime in 2006.

OK, all good so far – loaded ‘em up, referenced them, threw a TreeMap control on my form, compiled fine and then ran it, and… Bang!

Got a message;

Could not load type ‘Microsoft.Research.CommunityTechnologies.Treemap.NodeColor’ from assembly ‘TreemapGenerator, Version=1.0.1.38, Culture=neutral, PublicKeyToken=3f6121a52ebf7c82′ because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.

Turns out the problem is that I’m referencing a 32bit component from a 64bit application, and [...]

Microsoft Data Visualization Components on Windows 7

I’ve been playing around with the Data Visualization Components recently (looking to incorporate the TreeMap control with a SequioaView-a-like disk space analyser) but ran into problems getting the toolkit installed on Windows 7 RC1. Running the setup from the official page at http://research.microsoft.com/en-us/downloads/dda33e92-f0e8-4961-baaa-98160a006c27/default.aspx gets stuck looking for .Net Framework 1.1.4322;

Of course, being Windows 7, .Net 3.5 is already installed which should include .Net 1.1 but it looks like the Components installer is hopelessly confused. I couldn’t get the installer to believe we had something better than 1.1 already installed and I didn’t want to try and hack .Net 1.1 on top of Windows 7.

So, all I really needed were the “bunch of files” that come in the Component setup so [...]

“The breakpoint will not currently be hit. No symbols have been loaded for this document.” – VS2008

I’d been hacking around with Sharp Architecture (#Arch)a few months back but haven’t touched it recently. However, the release of 1.0 to coincide with the formal release of ASP.NET MVC 1.0 got me interested again, so I downloaded the latest and greatest to see what’s adoing…

There’s a great community around #Arch and it’s pretty easy to get your head around (assuming you’ve a basic grounding in MVC and NHibernate) and it even comes with a sample/tutorial app based on the ubiquitous NorthWind database. Now, being a cautious sort I figured I’d start by getting the NorthWind sample up and running, as this would prove I had all the dependencies installed and wired up.

All you (should) need to do is restore the [...]