Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

.NET & Funky Fresh

Check out the WPF book CB and I authored!
  • GPU Acceleration and 3D in Silverlight 3!

     Yes, you read that right.  Check out ScottGu's blog for the proof.  Let the good times roll...

  • It's Time to Update Your Silverlight Tools

    If you noticed, when Silverlitht 2 was released, they only released an RC1 of the tools.  Today, they have released the Silverlight Tools RTW.  You can get it here.  You can read some more details on Mike Snow's blog.

  • Unit Test WPF Data Bindings with Caliburn

    The Caliburn.Testability assembly contains various classes related to unit testing a UI. You can use the BindingValidator to validate data bindings on DependencyObjects, DataTemplates and Styles. The easiest way to access this functionality is through the static Validator class.  It has several methods for the most common scenarios related to unit testing data bindings.

    Note: This feature of Caliburn is only available to WPF due to limitations in the Silverlight API.  It is not in the Alpha download but can be found in the Trunk.

    Here is an example of a simple unit test:

    [TestFixture]
    public class The_UI_for_adding_a_new_customer
    {
        [Test]
        public void is_data_bound_to_a_CustomerModel()
        {
            var validator = Validator.For<AddNewCustomerForm, CustomerModel>();
            var result = validator.Validate();
     
            Assert.That(result.HasErrors, Is.False, result.ErrorSummary);
        }
    }

    The Validator class has several 'For' methods. In this case, we are using the overload that takes a type parameter for the UI and a type parameter for the bound data type. Simply call the Validate method and check the results to insure that all your binding expressions are correct. The ErrorSummary contains a textual representation of any errors that are found. The framework will walk the entire UI hierarchy checking data bindings on all dependency properties. It will check all elements for inline DataTemplates (such as ItemsControl.ItemTemplate) and, if found, check the template. All inline styles will be checked. Triggers on both DataTemplate and Style will also be checked.

    You can also validate the presence of a specific property:

    [TestFixture]
    public class The_UI_for_adding_a_new_customer
    {
        [Test]
        public void is_data_bound_to_the_CustomerModel_FirstName()
        {
            var validator = Validator.For<AddNewCustomerForm, CustomerModel>();
            var result = validator.Validate();
     
            Assert.That(result.WasBoundTo(x => x.FirstName));
        }
    }

    By using the WasBoundTo method, a test can use lambda expressions to do strongly typed validation of specific properties. There is also a WasNotBoundTo method for convenience purposes.

    Validation of items in resource dictionaries is also easy:

    [TestFixture]
    public class The_UI_for_adding_a_new_customer
    {
        [Test]
        public void is_data_bound_to_a_CustomerModel()
        {
            var validator = Validator.For<MyResources, CustomerModel>("addNewCustomerTemplate");
            var result = validator.Validate();
     
            Assert.That(result.HasErrors, Is.False, result.ErrorSummary);
        }
    }

    In the above example, the validator creates the ResourceDictionary called MyResources and then locates the resource with key "addNewCustomerTemplate." It then determines whether the resource is a DataTemplate, Style or DependencyObject and runs the appropriate validation.

  • Watch PDC Keynote Online?

    Anyone out there know if the PDC's keynote will be live on the web this year?  I can't be there and I'd really like to watch it, but I can't find any links or information to this effect.

  • Caliburn Moved and Documentation Added!

    Caliburn has a new home on CodePlex.  You can find it at http://www.codeplex.com/caliburn.  Additionally, I have added a full set of documentation that is available online.  The documentation loosely follows the samples I have created for the framework which can be found in the 'samples' folder.

  • Tallahassee Code Camp Resources Available

    If you attended my code camp talks on refactoring or dependency injection, you can now get the samples and slides.  Thanks to everyone who attended!

  • Caliburn Alpha for WPF AND Silverlight is Here!

    Caliburn is a framework designed to aid in the development of WPF and Silverlight applications. It implements a variety of UI patterns that are geared towards solving problems encountered in real-world scenarios.

     It's goals are:

    • Support building WPF/SL application that are TDD friendly.
    • Implement functionality for simplifying various UI design patterns in WPF/SL.  These patterns include MVC, MVP, Presentation Model (MVVM), etc.
    • Ease the use of a DI container with WPF/SL.
    • Simplify or provide alternatives to common WPF/SL related tasks.
    • Provide solutions to common UI architecture problems.

    This new version contains support for two primary features: Actions and Commands.

    Actions were primarily inspired by frameworks like Monorail and ASP.NET MVC.  Caliburn attempts to bring this methodology of UI architecture to WPF and Silverlight.  Using this feature allows developers to eliminate the need for code behind files by allowing UI components to bind directly to methods on other classes.  Actions supports a rich set of features such as auto determination of input parameters, databinding of return values, filters, automatic asynchronous code execution, UI updates based on action availability, etc.

    Commands are built on top of Actions and enable the GOF Command pattern.  This implementation is unrelated to the native WPF implementation and (IMHO) is superior to it in a variety of ways.  Commands have all the features of Actions.  Additionally, commands can be linked to form composite command chains.

    Now that I have the code up, I'll be spending some time blogging about how to use the specific features.  In the mean time, there are nine samples for both WPF and Silverlight that demonstrate the basic usage of these features.

    You can find the project site here.

     

  • Silverlight Version 2 RC0 Released

    Details here.  As far as I can tell from the docs, they removed a lot of things, made a bunch of things private or internal and changed the signatures of some things here and there.  I can only hope that I don't have to do massive rewrites of all my Silverlight stuff.  Does anyone from Microsoft want to tell us about any new features that were added?

    UPDATE: New features and breaking changes.

    UPDATE 2:  I've updated Caliburn and my super secret other project without any hitches.  Good job Microsoft!  The new control templates and rendering look much better too!

  • Caliburn Progress

    Some of you may be wondering about the status of Caliburn.  I'm presently working on the new version and am having great success making it compatible with both WPF and Silverlight.  It hasn't been easy, but it is going to work.  There's a lot of under-the-hood improvements in this new version and I think it's going to be great.  That said, even though I have decided to focus only on "Actions" for this first version, there is a lot of work that it takes to truly get it done right, and to provide decent test coverage.  My company has been busy lately doing some neat projects, including working with this ninja and also helping this company build some ground-breaking GIS goodness.  As a result, I've had to spend a little less time on Caliburn.  In spite of the slight loss of time, things are progressing well and I hope to commit the new code in about a month or so.  Thanks for your patience!

  • Tallahassee Code Camp

    If you call Florida, Georgia or Alabama home, this one's for you!  On October 11, 2008 we will be holding our 4th Annual Tallahassee Code Camp on campus at the great Florida State University (my alma mater).  Registration is open.  Please sign up ASAP.  (Personally, I'd like to see some of the ALT.NET guys come out, since I've met so few.)   We're looking to fill the day with speakers on a variety of topics.  Feel free to contact me if you would like to speak or if your company would like to sponsor the event in any way.  Looking forward to seeing you all there!

  • Silverlight Problems That Affect Me

    I've blogged previously about inconsistencies between SL 2 Beta 1 and WPF.  In my previous post I mentioned a few critical things that I felt would make it hard for WPF developers to move code between the two platforms.  Most of my complaints were not addressed in the updated Beta 2 of Silverlight, but I didn't expect them to be.  Some issues were just too complicated to try and fix that quickly.

    The purpose of this post is to mention a few more things I have found.  This list of "issues" comes directly as a result of my work in creating a common code base for Caliburn, for both the WPF and Silverlight platforms.  While many of these issues will be felt more painfully by developers trying to migrate their skills from WPF to Silverlight, most of them will also affect developers with no previous experience in this area.  Some of these problems are obscure.  In those cases, I will try and give some explanation of why it is important and how if affects the bigger picture of developing RIA's with Silverlight.

    • DepencencyObject, UIElement, and FrameworkElement all have internal constructors.

    For some reason (probably due to Silverlight's unmanaged goop) none of these fundamental base classes can be extended through inheritance.  They all have internal constructors.  The problem with this is, often times a developer has a need for a simple object with dependency properties.  In WPF I would just inherit from DependencyObject but in Silverlight the lowest level base class I can inherit from is Control.  But, I don't want a control!  This limitation also means that it's impossible to create lightweight UI components.

    • No Visual base class.
    • No Freezable base class.

    These base classes are not directly worked with by WPF developers most of the time.  But, their affects are felt nearly all the timeVisual, for example, is the base class that represents all renderable elements in WPF.  This plays an important role in everything.  They've gotten around this in Silverlight mostly by merging its functionality into other base classes.  Two areas related to Visual that represent functionality missing from Silverlight are printing and rendering to bitmap.  Freezable is an interesting class because it allows non-FrameworkElements to hook into the logical tree.  Thus things like transforms and brushes can be databound in WPF, but not in Silverlight.  The absence of Freezable and to a greater degree the absence of a logical tree has the most limiting and far reaching negative affect on Silverlight.  This is also the source of Silverlight's stunted databinding features, including the lack of ElementName binding.

    • IsEnabled does not exist on UIElement.

    This feature alone is enough to make it very difficult to build any real world business application with Silverlight.  Of course there are workarounds, but that would be painful.  The issue is that you cannot disable any part of the UI in Silverlight like you can in WPF.  With WPF, all UIElement descendants can be disabled; this includes panels, text boxes, buttons, etc.  With Silverlight the property exists only on certain classes (ContentControl, Slider and Thumb of all things).  This means I cannot disable things like TextBox and ListBox and I cannot disable an entire panel of controls.

    • FrameworkElement is missing the IsInitialized property.
    • FrameworkElement does not have an IsLoaded property.
    • FrameworkElement is missing the Unloaded event.

    The absence of these properties is not that big of a deal to me.  But, I'm used to them being there, and taking that for granted I was robbed of several possible "simple" solutions to some of the problems I was trying to solve.  Of most importance is the Unloaded event.  In combination with Loaded it enables developers to write specific code that responds to the addition and removal of an element from the visual tree.

    • No Selector base class.

    By itself this isn't major.  Indeed, at present, there aren't many things in Silverlight that could derive from Selector.  Mainly ListBox, but if they ever add a ComboBox (I can't believe this control is missing...) it should derive as well.  The overarching theme here is that the entire class hierarchy greatly differs between WPF and Silverlight.  No Visual, Freezable, or Selector.  Base classes can't be inherited (due to internal constructors) and important properties are missing.  As long as you stick to simple applications, this is fine.  But the minute you try some form of generic programming, often necessary in real applications....BOOM!

    • Exception (and its derivatives) have non-visible serialization constructors.

    Again, not a major deal.  Just know that if you are used to providing serialization constructors for custom exceptions, you won't be able to in Silverlight.  The serialization constructor of the base class is internal and there is no binary serialization in Silverlight either (which is perhaps the bigger issue).

    • DependencyProperty does not allow a way to declare metadata for a property.

    Normally in WPF you can declare more information about a dependency property, but Silverlight does not allow this.  Some examples are the default binding mode and whether or not a property affects layout or rendering.  I'm guessing that somewhere under the covers Silverlight is making some serious assumptions.

    • There is no LogicalTreeHelper and more importantly, no logical tree.
    • No name scopes.

    Though many WPF developers may not deal directly with these two pieces.  Their presence governs so much of the way that WPF behaves at runtime.  Not having these seemingly fundamental pieces has caused copious hair pulling and screaming.  This is also related to the absence of Freezable.  (Frankly, I'm still not sure how Silverlight works at all without these pieces.)

    • No custom markup extensions.

    Annoying!  I always use custom extensions and it is exceedingly important if you want to build any type of framework on top of Silverlight that eases common tasks.  Why are the existing markup extensions hard coded?

    • Some of the assembly names are different between .NET and Silverlight.

    This is not a big deal, and I attribute it more to WPF's poor assembly naming convention, because Silverlight actually does it more the ".NET way."  You'll need to know about this if you do multi-targeting though.

    • There are differences in the runtime behavior of the dynamic method API.

    Again, not a big deal.  But, it's confusing when there are public methods that you can call that will always throw an exception at runtime.  Pay attention to the words SECURITY CRITICAL in the intellisense.  If you see this, don't bother.

    • You cannot represent a class in Silverlight Xaml with a Name property.

    Weird.  Ok, to see what I'm talking about, follow these steps:

    1.  Create a new Silverlight project.

    2.  Add the following class definition to the project:

     

    3.  Change the markup for Page.xaml to match the following (make sure the namespaces match your project):

     

    4.  Make sure you add the event handler for the button to the code behind.

    5.  Set a break point in the click handler.

    6.  Run the application and click the button.  Using the debugger, drill into the Content property of the Button and examine the Name property.  You'll  see that the Name property is null even though you set it.

    • Binding is severely lacking.

    Let's just face it.  Silverlight data binding shouldn't even be compared to WPF databinding.  Silverlight's version is so stunted that it's embarrassing.  There's no element name binding, for starters.  This is one of the most important features in WPF data binding.

    In conclusion, I'd like to reiterate that I actually like Silverlight.  It has a lot of potential.  I just wish more attention would be given to the foundations.  If you get the core right, I can do anything.  Otherwise I'm limited to what Microsoft can imagine in their highly rushed dev cycle.

  • Reminder: Tallahassee .NET Architecture SIG Tonight

    If there's anyone out there who's in Tallahassee tonight, drop by our Arch SIG meeting.  I'll be doing an introduction to dependency injection by demonstrating a simple ASP.NET MVC application.  Hope to see you there!

  • I was going to say something but...

    Ian Cooper got there first.  He does a wonderful job pointing out what the heart of my concerns over the Entity Framework are.  And, if I may say so, what one of Microsoft's biggest deficiencies is: Learning from the past and learning from others.

  • What's Up With Caliburn?

    After asking some questions of the community and doing some thinking, I've finally devised a plan of action for Caliburn:

    • I'm going to freeze the current source code where it's at.  Anyone who is using it can be assured that it's not going anywhere.  However, I will not be making additional changes to that branch. 
    • In the next few weeks I'll be committing a brand new code base that will be the foundation for Caliburn from here on out.  There will be a single code base that builds for both WPF and Silverlight 2.0.
    • I'll be focusing my work on the ActionMessage feature from Caliburn.  The API will be changing slightly, but the core features will remain the same.  This is necessary to enable Silverlight.  The reworking of code will also enable several other improvements such as: performance enhancements, better exceptions, more extensibility points and in many cases, simpler code.
    • The assemblies will be more componentized, enabling developers to more easily pick and choose features.  For example, my new architecture has a Caliburn.Core assembly and a Caliburn.Actions assembly.  In the future, I may add things like Caliburn.Events, Caliburn.Commands, etc.  I am convinced that this is a good architectural decision overall and it has the added benefit of helping Silverlight developers to keep their download size small, by selective use of features.
    • I will be providing a full unit test suite.
    • As I hit various milestones, I'll be building simple demo applications and blogging about the use of various features.
    • When I am satisfied with the feature set and quality of Caliburn.Actions I will make an official release.  At that time, I will consider what feature to work on next, but in the mean time, I would love to here from you.

    This is a fairly daunting task, but I'm pretty excited about it.  "Actions" were always the heart of Caliburn, in my mind, so I'm resolved to focus on getting it done right.  Last night I finished getting my prototype to compile for WPF and Silverlight, so I'm on my way.

    Since it is going to be a challenge creating a common code base for both platforms, I'm going to be blogging about that as well.  I've got two posts coming up that are related.  The first will detail using NAnt to build WPF and Silverlight apps and the second will detail several of the differences between the two platforms.  Stay tuned!

  • Prism and Caliburn's Future

    First I'd like to say that I'm stoked about the work the Prism team has been doing.  I have to admit that when they started out in January to deliver a set of guidance for building composite WPF applications, I was skeptical.   But they have come a great distance and I am truly proud to have been able to contribute to the effort as part of the advisory board.  I think their work is a huge success for Microsoft and more importantly to the .Net community at large.  I believe this had a great deal to do with their interaction with the community, their transparency, use of Agile methodologies and tons of unit testing to boot.  I hope this becomes a trend for Microsoft.

    With the first release of Prism right around the corner, I've been thinking more about what direction I'd like to go with Caliburn from here on out.  Before I get into that, let me back up and talk a little about how Caliburn came to be...

    Several years ago I started playing with WPF, building various little applications, experimenting and generally being impressed with the framework and having a good time as well.  In 2006, the Microsoft Codemaster Challenge came along and CB and I decided to see how far we could take WPF by building an online multiplayer game.  It turned out pretty well (enough to land us in the top 20 out of over 4,400 applicants world-wide) and we learned a lot about WPF in the process.  Unfortunately we were unable to pursue are game development dreams at that time, and were forced into building "real world" applications.  At that time (early 2007) I had begun experimenting more with UI architectures in WPF, originally inspired by Crevier and Gossman's blogs.  There were certain command-related patterns that happened repeatedly when trying to build an MVP style design.  These patterns often resulted in tedious boiler-plate code.  To eliminate this tedium, I created the ancient ancestor of Caliburn's ActionMessage.  I worked on this for a bit, improving it for my own use and eventually wrote this article, describing an early, crude version of the framework.  I worked on this version a bit more and we eventually used it on a real project of ours, a smart client for a large state organization.  Over the coarse of this project I realized a number of shortcomings, improvements and features I wanted to work on.  In late 2007 I began officially working on what is now Caliburn by starting from scratch and building a framework based on a bit more real-work experience.  In the early part of this year, I continued to add features and eventually officially published the framework.

    A lot has happened since that time.  Mainly, I've built more WPF applications, been involved with Prism and added tons of features and improvements to Caliburn.  I've found advising Microsoft on Prism and working on Caliburn simultaneously to be a constant struggle.  Some days I hated Microsoft for trying to build what I had already built, other days I was strangely relieved by the thought.  I've found that running my small open-source project is quite challenging (props to the big boys who do it well) and have recently felt the stress mount.

    Things changed for me the other day.  I was looking through some of the Prism code in preparation for our regular meeting.  I hadn't looked at it in a while due to the fact that I had to miss several meetings for scheduling conflicts.  I came to their EventAggregator implementation and thought to myself "Dang, that's a really nice implementation."  I looked at it a bit more and realized, "Hey, I like that better than my implementation!"  Well, actually Caliburn has two different implementations that are completely different solutions to the same problem, but I like the Prism solution better than both of mine!  I began to think about refactoring my solution, but then I though "Why couldn't I just use the Prism aggregator in my applications?"

    This brings me to Caliburn's future.  Lately I've been feeling that Caliburn has grown rather large and difficult to learn (something I criticized both CAB and Acropolis for).  I haven't had time to fix bugs, document, test, provide an RI, etc. - and I feel like the project has gone out of focus.  Also, when I look at Prism, I see a large overlap in features with Caliburn:

    1. EventAggregator - I actually like the Prism implementation better than mine.
    2. RegionManager - This is virtually identical to Caliburn's CompositionMangaer.  No really, they are practically the same implementation.  (I guess they took some of my advice.)
    3. Module Loading - This is also very similar to Caliburn.

    As I have struggled with managing an open source project and wrestled with how to  divide my time between features, bugs, etc.  I've wondered "Wouldn't everything be easier if I just let Prism do what it does best and Caliburn do what it is good at?"  If Caliburn supports a unique set of features, apart from Prism, and could be used as a logical extension to Prism, then I could focus on a smaller set of features, make sure they work well and are consistent, provide ample documentation and samples and actually get some decent test coverage.  (Not to mention reclaim my home life...)

    So, I'd like to get some feedback from you.  I have no idea how many of you are using Caliburn our how you would feel about this change in direction.  Please leave me a comment because I don't want to make a decision that is going to seriously cripple anyone.  There are several paths I could take Caliburn and I'd love to hear what you would favor:

    1. Continue development as is.
    2. Shamelessly steel the Prism EventAggregator and replace both my implementations with theirs.
    3. Remove features duplicated in Prism from Caliburn - event aggregation, ui composition and module loading.  Users who want these features can use Prism in combination with Caliburn.
    4. Take a hard dependency on the Prism framework and build on top of it.  This would further reduce duplication and enable the two frameworks to work seamlessly as one.
    5. Scrap Caliburn, but take the unique features (like ActionMessage) and implement them as part of PrismContrib to better flow into the existing community surrounding Prism.

    Honestly, I'm leaning towards 3, 4, or 5.  I could easily move through these as a progression, one at the time.  However, I want to be clear that I don't want to cause undue pain for those who are using Caliburn at present, so please leave a comment.  If everyone screams "NO!" then we stick with option 1.  But, the truth is, I really have no idea whether Caliburn has 2 or 200 people who are using it seriously and would love to find out anyway.  Would a future with complimentary features between Caliburn and Prism be meaningful for you?

More Posts Next page »

Our Sponsors

Red-Gate!

Proudly Partnered With