Archive for July, 2008

WPF Master Pages (kinda sorta)

I decided to build a simple project management application in my quest to wrap my head around WPF.  So far I set up the database, got an Entity Framework model happily binding, and started writing CRUD “pages” (the TabItems of a TabControl as shown in the GUI shown).

image

These pages share much of the same presentation and logic and, after writing two of them, I knew I had to refactor them somehow.  Some kind of “master page” would work well here.  I will just define the entity-specific controls and the data calls for each page and the rest of the presentation and logic will live in non-repeated harmony in the master page.

Well, my first idea, subclassing a XAML-based UserControl turns out to be very tricky to get by the compiler and generally a bad idea.

These links provide some valid ways to implement master page type functionality in WPF:

I’ll share some code later once I am happy with my implementation.  One issue is that you can’t bind between controls in different ContentControls (as noted in this comment), which I need for this application.  I know there has to be a better way…