going commando on code

In WPF, there are a fixed number of “system” themes which mimic the themes from the various favors of the Windows Operating System. The system themes are described on MSDN, where you can also download the default Styles and ControlTemplates applied to the native WPF controls.

Note: The .NET 4 versions of the WPF themes have yet to be released.

One of the system themes is Aero.NormalColor, which is the default theme used when a WPF application is run on Windows Vista or Windows 7. There are two problems with the default Aero theme.

The first issue is that the selected item(s) in a ListBox or TreeView do not get the true Aero “look”. The second issue is that the Aero theme was designed originally for Windows Vista. With Windows 7, some the colors were tweaked while the overall “style” looked the same.

ListBox with the default Aero look

This is a far cry from the look seen in the Windows 7 Explorer. The default Aero style for the ListView is closer, but still uses the Windows Vista style colors.

The good thing about WPF though, is that the default Styles and ControlTemplates can be easily customized. In the Windows7Theme1 project, I’ve created Styles for the ListBox, ListView, and TreeView that will give them a look that more closely resembles Windows 7.

The Styles are lacking in a few spots. When using a GridView with the ListView, the column headers need to be updated to match the Windows 7 look. In Windows 7, the TreeView extends the selection the entire length of the control. In addition, the expander buttons fade in and out based on whether the TreeView has the keyboard focus and/or if the mouse is currently hovering.

I’m not really a web developer. I’ve dealt mostly with Windows-based applications through-out my career. I know C# and .NET, which translate well to server-side things with an ASP.NET site. But, there is much more to it than that.

So I didn’t want to try to build a full-fledged site. Especially, for something that is more of a side project. I turned to BlogEngine.NET, which is a polished and well established open-source blogging platform.

Installation

I chose to build BlogEngine.NET myself and deploy that to my webhost using an FTP client. I wanted to go this route just in case I had to customize the binaries. I did run into two issues.

The first issue had to do with (accidentally) entering invalidate data into the geo-locations fields. I was able to resolve this by manually updating the settings in the database.

The second issue had to do with using a .NET 4 app pool. I didn’t take the time to figure out this issue, since switching to .NET 3.x fixed the issue.

Aside from that, the setup was really pretty smooth and well documented.

Theming

For the theme, I started with the Paalam theme which was adapted by Chris Blankenship. I liked the over all layout, which would allow me to make minor tweaks.

The first step was to “go green”, as that was my color of choice. Using Google Chrome, you can right click various elements and inspect them. Using this tool, you can then see what CSS styles are applied. This allowed me to find and customize the various colors.

The next step was to customize and add some icons. I’m also not a graphic artist, but again to save money I try my best. I decided to go ahead and purchase the Blockie icon set from IconDock. It definitively saved me a lot of time, while giving me a look I liked.

For the banner, I originally used some of the Blockie icons with a customized background. But wanted something a little more fitting to the CodeNaked name. Thankfully, Spoon Graphics has several tutorials for creating vector illustrations. I based my “naked dude” on the Mechanic tutorial.

The only trouble I had was with the default keyboard shortcuts in Adobe Illustrator. As a Windows guy, I’m used to having Ctrl+Y mapped to the redo operation. In Adobe Illustrator, this switches you to an “outline” view. The outline view does not show any strokes or fills. I finally figured out how to change back to the “preview” view, so I could fill in colors.

For the header background, I referred to this tutorial. It has a nice walk through of creating the “sun ray” effect, as I call it, and applying a texture.

Analytics

Finally, I wanted to be able to track visitors to my site. I used to have a WordPress blog, which had some fancy charts and statistics. BlogEngine.NET doesn’t have any built in analytics, but it is very easy to integrate Google Analytics. With that setup, I can now view pretty graphs and charts based on traffic to my site.

I have been working deeply with WPF for about 3 years now and have seen quite a few samples, blogs, etc. of WPF code. There’s one aspect I wanted to dive into today and that has to do with using StaticExtension over RelativeSource.

For example, let’s assume you want to bind a TextBlock’s Text property to it’s own Foreground property. You can do this in XAML using two different ways.

The first uses StaticExtension to retrieve the static Self property from the RelativeSource type:

The former appears to have the benefit of reusing a single instance of RelativeSource with it’s Mode property set to Self. This, of course, implies that the latter will create new instances each time the line is processed. But this is not entirely true.

Using .NET Reflector, we can see that the ProvideValue method of RelativeSource will actually return it’s own Self static property. So effectively, a new instance of RelativeSource is created, but is not retained by any associated Bindings (as they will reference the value in the static Self property).

Ultimately, it comes down to whether StaticExtension is faster/better at providing the Self static property than the RelativeSource (via their respective ProvideValue methods). To determine this, we have to analyze the operations they perform.

Both will need to be constructed when loading the XAML, in order for their ProvideValue method to be called. Both will have their parameters analyzed/constructed in order to call the appropriate constructor/property setting.

I believe the key difference is that the StaticExtension must perform reflection on the given type in order to get the value of the specified property/field. This includes resolving any types based on the XAML namespace aliases, which can be expensive in it’s own right.

Using .NET Reflector, we can see that it’s even more complicated than that. It must also determine if the specified member name is a field or a property, using two loops. The first loop looks for a static field with the specified name. First in the specified type, then in each of the base classes. If a field with the specified name is not found, then it repeats the process looking for a static property.

Reflection is considered slow enough as it is, but presence of the two loops will only make it slower. I assume it is coded this way so that member hiding, using the new keyword, will be properly resolved.

So if you have fallen into the habit of using StaticExtension over RelativeSource, like I did, then I’d recommend you change your ways!

When I first quit my big corporate job with dreams of start up money, I had incorporated under CodeNaked, Inc. Luckily, I also registered the associated domains, since they’d most likely be snatched up by now. I didn’t really know what I was going to do at that time, just “projects” that I thought were interesting and that could potentially make money. I had a long list of possible projects.

I ended up ditching CodeNaked and founding another company, SQL Farms, with a buddy of mine. During that time, we built a fairly kick-ass product called SQL Farm Combine. It was written from the ground up using C#/.NET and WinForms, with a little C++ for licensing. The company ended up folding anyway, but it was a fun ride. I learned a lot, especially about end-to-end commercial application development.

Since then I have been working as a contractor, focusing on WPF and Silverlight components. This is definitely my current area of expertise, but I tend to dabble in lots of areas.

One “hot topic” is smart phone application development, which interests me. Largely because, it is fairly easy to get setup with one off applications. I obviously started reading up on iPhone development and have since started reading some Android development books.

I’ve been flying under the radar for quite a while now. I had maintained a blog a few years ago dealing mostly with C#/.NET and TSQL, but that has since languished. I have wanted to start blogging again for a while now, but could never really find the time. But, as they say, you have to make time. So that’s what I’m trying to do here.

I’d like this blog to cover my adventures through various development projects, whether or not they go anywhere.