Tech Tock

Time is of the essence.

No x:Type, No Problem

I had an interesting problem this week.  I needed to use a default template on a subclassed control.  Ordinarily, that would just be:

Style=”{StaticResource {x:Type BaseClass}}”

Of course in Silverlight, there is no x:Type.

The solution I used was to make an attached behavior that takes the class that has the style, finds the style in the resources and applies it.

The problem

Using a TextBox as an example, here’s some default styling that doesn’t get applied to the subclass:

        <TextBoxText=“Auto Styled”/>

It ends up looking like this:


The Solution

With an attached behavior, it can look like this (the bottom TextBoxSubclass has the default TextBox style applied):

        <TextBoxText=“Auto Styled”/>

The attached behavior is pretty simple:

        static void StyleTypeValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
            //need to be loaded so the visual tree can exist and be traversed
            (sender as FrameworkElement).Loaded += (sender1, args) =>
                    (sender as Control).Style = (Style)FindResource(sender, e.NewValue.GetType());
        static objectFindResource(DependencyObject start, object resourceKey)
            var nextUp = VisualTreeHelper.GetParent(start);
            while (nextUp != null)
                var fe = nextUp as FrameworkElement;
                if (fe != null)
                    var result = fe.Resources[resourceKey];
                    if (result != null)
                        return result;
                nextUp = VisualTreeHelper.GetParent(nextUp);
            return null;


I think its exceedingly obvious how you could apply this universally as a default style on the subclass.  This looks like it has potential to be a pattern to compensate for other Silverlight omissions too.

You can download the full tiny demo on GitHub.


November 28, 2011 Posted by | Uncategorized | | Leave a comment

Caliburn Micro–Soup to Nuts

Just getting into Caliburn Micro for a new Silverlight project.  I was a bit disappointed when I saw that the official cheat sheet was “coming soon”.  Rob Eisenberg made this excellent 9+ part Soup to Nuts tutorial and the Soup to Nuts section of the documentation has content, so the documentation for Caliburn is actually pretty good.  Of course, both these resources suffer from the death of the long form.  Once again I had to convert them to pdf so I could read them on the subway.  Maybe next time I’ll try this utility.

In any case, I’m excited to try out Caliburn Micro and my experience so far has been positive, but more on that later.

August 8, 2011 Posted by | Uncategorized | , , | Leave a comment

WPF in 60 Seconds

Or:  So Much WPF, So Little Time

I’ll be presenting on WPF at the September 21st .Net Meetup.

A breezy tour of topics in WPF from the ground up with demo examples and source code.  Each topic will be given a one minute treatment.  For anyone interested in, new to, or learning WPF you can see the scope of the platform and see what you want to learn.  For anyone working in WPF, enjoy the highlights of your platform.  You might even see something you’ve missed.

Everything will apply equally to Silverlight, subject of course to this diagram.

August 11, 2010 Posted by | Uncategorized | , , , | 2 Comments

Cider – A Bitter Brew

Cider is the name for that incredibly slow and useless XAML preview in Visual Studio 2008.  Instructions on how to turn it off can be found here.

July 22, 2010 Posted by | Uncategorized | , , , | Leave a comment

Dispatcher.BeginInvoke: UI Duct Tape

image It’s a standing joke on my current Silverlight project that when something isn’t working, just try Dispatcher.BeginInvoke.

Its funny because its true.  When there’s property setting or UI resizing or several other common UI related problems, putting the next statement on the Dispatcher to let an operation complete first is just the trick.  Handy as Duct Tape.  Case in point, the focus at startup issue.

May 13, 2010 Posted by | Uncategorized | , | 1 Comment

Focus on Silverlight App At Startup – Problem Solved

I finally figured out the way to set focus to a Silverlight control on start-up:  just set focus to your app, then set the control focus on the dispatcher to give the app time to process whatever it needs to when it gets focus.  In other words, in the root visual constructor use this code:

Dispatcher.BeginInvoke(() => YourControl.Focus());

This may be the first (and probably the last) actual Silverlight mystery I have solved.  A couple months ago, I was searching the internet for the way to do this and found absolutely nothing.

Yippee-Kai-Yay for me 😉

April 20, 2010 Posted by | Uncategorized | , , | 3 Comments

Visual Studio INotifyPropertyChanged Snippet

I just made my first Visual Studio snippet.  It’s really easy.

There’s a consensus developing that says dependency properties are usually too heavyweight and people are using INotifyPropertyChanged instead.  I miss the snippet that creates a dependency property, so I made a similar snippet for INotifyPropertyChanged.  You can download the code here.

To make a snippet, just go to Tools / Code Snippets Manager and find a snippet to start with.  I started with the “Define a Dependency Property” snippet since I was doing almost the same thing.  The Snippets Manager will tell you where that file is:


Go to the file system and copy the file to your My Code Snippets folder.  If you highlight the folder in the Code Snippet Manager, it will tell you where it is — you can copy the path from the location field.  The file is an xml file, but needs to be named “.snippet”.

Editing the file is very straightforward and the snippet will be available immediately – no restart needed.

One interesting thing about the code is that I’m using a simple method to do all the work:

I basically combined this CodeProject work with Jeff Yates object.Equals idea from here in order to handle both reference and value types in a single call:

Here’s how the snippet comes out by default (the myNames and type are the replaceable fields):

int _myField;

public int MyProperty
    get { return _myField; }
            ref _myField, ref value);

This is the method that does a check and notify in the base class:

protected bool CheckPropertyChanged<T>
      (string propertyName, ref T oldValue, ref T newValue)
            if (!Equals(oldValue, newValue))
                oldValue = newValue;
                return true;
            return false;

February 11, 2010 Posted by | Uncategorized | , , , , , | 3 Comments

.Net Meetup – FX Fun

Went to the .Net Meetup Tuesday night and had a great time.  Plenty of interesting discussion and some laughs too. (All that and free pizza too). Highly recommended:

        if (yourGeekiness >= myGeekiness)

Daniel Chait (my boss 🙂 led the meeting.  The below info is mostly from Dan’s notes which he wrote on the overhead in real-time (I take credit for any errors or omissions).  As you can see, if you didn’t attend, you missed a lot.  These are mostly just the topics.  Each one generated lively discussion:

PDC 2009 started today:

Microsoft CodeName “Dallas” announced.

Microsoft “Micro Framework” open sourced:

(not including some stuff like Crypto etc)

Scott Hanselman had a podcast about it?

Azure going live in February (cloud services)

Business Model announced.

Cloud Computing : Compare Azure vs others

Vs Amazon EC2?  Amazon gives you a virtual machine, whereas Microsoft gives you specific services (i.e. web, database, WCF services).  Also cloud-based Pub/Sub model.


– For co’s & individuals

–Co less than 3 yrs. old, less than $1MM, private

– You get all Microsoft stuff basically for 3 yrs. free.

– Check out the “Program Guide” off the website for more details


– You get VS, SQL Server, and Blend, etc. to get started

– 3 year license for free


– Part of Office 2010 (was codename “Gemini”)

WPF Grid Controls?

– Using DevExpress (WinForms grid)

– Infragistics – not much new there. tech support pretty good.  glaring bugs in new versions.  difficult upgrading between different versions due to problems with style upgrades

– WPF Toolkit has a grid control: very basic, missing a lot of features (i.e. Filtering etc)

– XCeed well regarded. Been around the longest, full featured.  Cons: tech support iffy.  Licensing may be problematic – issues when you convert from demo to licensed version.

Data Direct products:

– XML converters

– Database connectors

– Difficult licenses

.NET Framework v4?

– Tasks, parallel stuff –

– WorkFlow changing a lot in V4 as well

– Documentation is very minimal at this point

– Maybe some good PDC content coming out?  i.e.

– Maybe some channel9 stuff to find?
Hello Workflow 4

WF4.0 A First Look

What do people actually use WF for?

– Sharepoint development.  Basic stuff.

Architecture in .NET Question: Model Approach to Database Access?

– ORM Software: Developers make clean code which makes horrible queries

– Call Stored Procs from software: nice queries but ugly to call

Entity Spaces

– Experience: Easy to use, decent performance but on a simple app

– In ALL cases, need to analyze queries in detail, can’t just rely on the ORM to sort it out

– Microsoft Entity Framework 1.0 – not full featured enough

– New one coming out

Linq2SQL is dead 😦

– Linq2SQL used a GUID(?) which killed query caching

– NHibernate – “granddaddy of them”.

– Cons : “Has a case of the Java’s”.  XML Configuration, FactoryFactoryFactory…, etc.

GRAND CLAIM: Try to avoid open source:

– Hmm…

– IF something is just a small, weekend project on CodePlex, probably worth avoiding.  But, like, …

– NUnit


– NCover

– NMock, moq, RhinoMock

– Log4Net, nlog

– log better, easier to configure

– Fluent NHibernate

– The MONO project

– Need to treat it more like “code” than a “product” from a vendor.  Actually understand the code don’t just consume it.

– Open source projects are driven by enthusiasm

– JQuery plugins for example

One user mono in production spoke up.

– Follows the Pareto Principle – for example doesn’t use code signing

– Implementing silverlight (i.e. Moonlight) which works on the iPhone

– Castle project – ActiveRecord implementation – says it’s at least as good as say RoR – just does property setting in code, built on top of NHibernate, scaffolding, etc.

The Munawar principle – 20% will be good, 80% will be garbage

FBK #2: Sturgeon’s Law – “90% of everything is crap”

NCover – code coverage tool

“Where’s my LINQ2 Mainframe?”

SubSonic – open source framework for stuff –

– “A Super High-fidelity Batman Utility Belt that works up your Data Access (using Linq in 3.0), throws in some much-needed utility functions, and generally speeds along your dev cycle.”

[long discourse about non programmers.  in short, they are inconvenient.]

AJAX / ASP.NET – still buying into it?  As opposed to WPF / Silverlight / Flex?

– Corollary – as a novice, what should I be getting in to

– Corollary 2 – if I want to get out of ASP.NET and get into WPF and realtime .NET desktop apps, how do I do it?

– Endless debate about Silverlight vs Flex

– Silverlight can be applied-ish to WPF knowledge

– Flex VERY easy to learn

Silverlight vs WPF?

– Third party controls maybe a bit better in WPF at present

– If heavy desktop integration, use WPF, else Silverlight by default

– Silverlight Out of Browser – still in the sandbox but just looks like the browser is missing.

– Databinding in Silverlight not nearly as good as WPF.  A bit better in 3.0 but still not great

[spontaneous demo of Castle ActiveRecord]

Good localization solution?  Want to translate our site into multiple languages….

– Sharepoint can do some of this but not ALL languages

– New version of Sharepoint (2008?) does this

– Beware of language specifics (i.e. German has long words)

– Maybe any content management solutions that exist?

– How to handle caching?

– Generate static content or regenerate on the fly every time?

– See for more

November 19, 2009 Posted by | Uncategorized | , , , , , , , , , , , , , , , | Leave a comment

@Lab this Week

A weekly roundup of interesting things I hear about at the Lab, since this is the first one, it covers a bit more than a week.

A couple of Flex developers commented that WPF and Silverlight are so much more mature, easier and feature rich.  They were half right as this popular diagram shows:

Some UX designers working with Expression Blend said it’s not horrible, so now I don’t feel too bad asking them to use it.

This fun character interaction chart was much discussed (small version here).  I think it gives an interesting summary of some great movies.  It may bear a resemblance to the Napoleon March Map.

And the movie Primer, with the scribbly chart, is about time travel.  One commenter suggests the creator of the chart didn’t understand the movie, but it looks like a movie I’ve got to see.

Who builds domain specific languages? I just met a couple of guys @Lab and it makes more sense than I thought.  One application is to build a really small and focused keyword set so users can write programs they can validate and maintain.

MongoDB (from “humongous”) “is a high-performance, open source, schema-free document-oriented database.”  That’s heavy verbiage to say you can store and retrieve and you don’t have to design your database, whatever you send it, it will just save for you, no tables, no troubles.   Looks great for a lot of web storage needs. We had a seminar @Lab and document oriented dbs seem to have a definite niche. CouchDB is another product in the space.

Its hard to see a parade when you’re 20 stories over it, but throwing stuff was loads of fun:

06-11-09_1127 (2).croppedjpg
A Million Stringless Kites
Also mentioned Treasury, F#Scrum, Java Meetup 11/11, VS 2010 Beta 2 Now Available, Apple Mouse, More Mice, Free Money From High Frequency Trading, Agile Boston 11/25

November 7, 2009 Posted by | Uncategorized | , , , , , , , , , , | Leave a comment