Tuesday, May 01, 2007

Update of the WPF integration for the validation application block

In WPF databinding you can bind not only to a property of an object, but also to a path. For example, in the quickstart of the validation application block, the customer object contains an address object. You can now databind a textbox to the city with the expression Address.City, using the common dot notation:

<TextBox Text="{Binding Path=Address.City}"/>

I have now updated the ErrorProvider of the WPF integration for the validation application block to support these data bindings. You can now conveniently nest all the databound controls into a single ErrorProvider, and get automatic validation of the customer and address fields.

You can download the update here.

Here are some answers to questions I received about the WPF integration:

Question: How do I compile the sample application that is contained in your zip archive?

Answer: First, make sure you have the source code of the Enterprise Library 3.0 installed. You can find the business entities in the Quick Starts/Validation/CS directory. You can also extract the zip archive of the WPF integration into that directory and add the projects to the ValidationQuickStart project, and all references should be set.

Question: Can I use the EnterpriseValidationRule directly in my XAML, without using the ErrorProvider?

Answer: Yes, for example:



        <Binding Path="LastName">


            <my:EnterpriseValidationRule SourceTypeName="ValidationQuickStart.BusinessEntities.Customer, ValidationQuickStart.BusinessEntities" PropertyName="LastName" RulesetName="RuleSetA"/>






Tuesday, April 24, 2007

WPF integration for validation application block

You can now download the code for the WPF intergration for the validation application block of Enterprise Library 3.0.

Please refer to my previous post for an explanation of what this integration does. The zip archive you can download contains two projects:

The Validation.Integration.WPF project contains the two classes EnterpriseValidationRule and ErrorProvider that you can use in your own projects (under BSD license).

The WPFValidation project can be compiled together with the validation quickstart from the Enterprise Library 3.0. It is the same quickstart sample rewritten for the WPF integration.

Download the code here.

I would like to thank Tom Hollander from Microsoft Patterns and Practices for his encouragement to publish this code.

Let me know if you have any questions or feedback.

Update: I have published an update and answered some questions here.


Tuesday, March 20, 2007

Enterprise WPF: Validation

I am developing an enterprise application with WPF.

WPF is great, but it is very new and not many enterprise applications have been developed with WPF so far. Several things that are part of most enterprise applications are not very well supported with WPF, and you need to put in some extra effort.

One example is validation. Validation happens when the user is entering data into a form, and the application has to validate the user input before accepting it. Some text fields can have only a certain length, a date field has to contain a valid date, the start date cannot be later than the end date, and so forth.

How are developers implementing validation? For example in ASP.NET, there are several validation controls. The ASP.NET developer puts these validation controls on the page together with the textboxes and other controls for the data input. A CompareValidator to check that the start date is before the end date, a RegularExpressionValidator to check for a valid email address, etc.

Is this a good technology? Yes, because many enterprise applications are implemented that way, and they work well. But no, because your validation code is mixed into your user interface layer. In an enterprise application you would like to have your validation logic in your business layer. This is the better place for several reasons:

  • In a distributed application (web, smart client, or client server), you cannot trust your user interface layer and have to perform the validation again on the server, duplicating your validation logic.
  • You may have to support more than one user interface, e.g. a web and a smart client interface. While you can reuse the validation logic in the business layer, you have to develop another validation for each UI.
  • You may have to provide different forms for entering the same type of data, e.g. a customer address and an employee address. Again more versions of the same validation.

With potentially many versions of the validation logic, every change in requirements would become a maintenance challenge.

In comes Enterprise Library 3.0 and the Validation Application Block (VAB), to the rescue. The VAB lets you define validation rules on your business objects using configuration and attributes.

Here is a simple example from the VAB quick start, that shows how to define a simple validation rule on a FirstName property, that validates the length of the string:

        [StringLengthValidator(1, 50, Ruleset = "RuleSetA", MessageTemplate = "Last Name must be between 1 and 50 characters")]

        public string LastName


            get { return lastName; }

            set { lastName = value; }


VAB includes a whole range of validators. To avoid duplication of the validation logic, VAB comes with integrations into Windows Forms, ASP.NET, and WCF. Unfortunately, WPF integration is missing. I also do not like the ASP.NET integration, but that would be another blog post.

It is rather unfortunate that WPF integration is missing from the VAB, because WPF's validation support is limited. The basis for a validation framework exists in WPF, and it is actually very flexible. WPF validation is based on DataBinding - a Binding can have ValidationRules associated with it. Unfortunately there is only one ValidationRule included with WPF at this time. This is illustrated in a great article on CodeProject by Paul Stovell.

In this article Paul builds a WPF validation framework on top of the IDataErrorInfo interface. This interface lets you define validation logic on your business objects. The validation logic is defined procedural, though, not declarative. You can see an example for this in Paul's article.

I have now implemented a WPF integration of the VAB based on a modification of Paul's ErrorProvider. The ErrorProvider lets you wrap a part of the user interface that is based on the same DataContext. The ErrorProvider automatically adds an EnterpriseValidationRule to all data bindings. The EnterpriseValidationRule uses the validation rules defined using VAB on the property that is bound to.

Here is a XAML version of the VAB quickstart:

    <my:ErrorProvider x:Name="epCustomer" RulesetName="RuleSetA">

      <Grid Margin="5">


          <ColumnDefinition />

          <ColumnDefinition />



          <RowDefinition />

          <RowDefinition />

          <RowDefinition />

          <RowDefinition />

          <RowDefinition />


        <Label>First Name:</Label>

        <TextBox Grid.Column="1" Text="{Binding Path=FirstName}"/>

        <Label Grid.Row="1">Last Name:</Label>

        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=LastName}"/>

        <Label Grid.Row="2">Date Of Birth:</Label>

        <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=DateOfBirth}"/>

        <Label Grid.Row="3">Email:</Label>

        <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Email}"/>

        <Label Grid.Row="4">Rewards Points:</Label>

        <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=RewardPoints}"/>



Note that all that is added to the XAML code is the ErrorProvider, and we are getting automatic validation based on the validation rules of the bound business objects.


Friday, February 16, 2007

WPF on the 38th floor

In my latest project I am working on a WPF prototype. I cannot show you anything of the WPF yet, but here are two pictures from the 38th floor (Frankfurt Hauptbahnhof, Frankfurt Messeturm):


Monday, August 14, 2006

The Atlas update panel

The technologies comprising AJAX have been around for several years, but their inherent complexity forestalled widespread adoption. AJAX frameworks are designed to make AJAX development easier. It is these frameworks that enable the whole Web 2.0 motion (and corresponding hype).

Still, even with a framework client-side development with Javascript and its ideosyncracies and limited tool support remains challenging when compared with the control centric, object-oriented approach made popular by ASP.NET.

Atlas is Microsoft's AJAX framework, based on ASP.NET 2.0. It comes with server-side controls that encapsulate the client-side functionality. Most useful is the UpdatePanel control, that allows the developer to convert any events raised from traditional ASP.NET server controls from full page postbacks into flicker-free AJAX-style partial page updating.

Using the UpdatePanel you can improve almost any ASP.NET page that does postbacks to update its contents. You don't have to be an AJAX insider nor a Javascript wizard to achieve this, any developer familiar with ASP.NET should be able to use the UpdatePanel. While Atlas is still in beta, or technology preview as these things are called nowadays, it comes with a go live license and is stable enough to be used in production sites now.

Bertrand LeRoy and Matt Gibs who are working on the UpdatePanel control at Microsoft have written an O'Reilly shortcut "Atlas UpdatePanel Control" that shows you how to apply the UpdatePanel. After some introductory explanations they show three well-chosen real-world examples, that are so close to common ASP.NET pages that you immediately understand how to apply the UpdatePanel in your own websites. The examples also include many tips and best practices on other aspects of ASP.NET and Atlas programming, with references for further study.

Shortcuts are short introductions to a brandnew topic that you can download as a PDF file. Until a book with a complete coverage of the Atlas framework and corresponding control toolkit comes along, this one shows you all you need to know to get going with the update panel, and is highly recommended.


Monday, August 07, 2006

How to localize the ReportViewer control in ASP.NET 2.0

The ReportViewer control in ASP.NET 2.0 allows you to display SQL server reporting services style reports. The reports can come from a SQL server reporting service (server mode), or from the website itself (local mode).

If you run the ReportViewer in local mode, you can also bind it to your business logic directly, instead of having to bind it to a database directly.

I found localizing the reports a bit tricky and not well documented, so here is a step by step guide:

  • When I installed Visual Studio 2005, only the English version of the report viewer itself was installed. The toolbar buttons for searching, exporting, etc. were displayed only in English. First you have to download and install the Microsoft Report Viewer Redistributable 2005. You will need to install this even if you have Visual Studio 2005 installed, as otherwise the installation of the following download will crash (at least it did that on my machine).

  • Now you can download the Microsoft Report Viewer 2005 Language Pack. Go here, choose the language from the dropdown, download and install for each language that you want to support.

  • If you run the report viewer now, you can see the localized toolbar.

  • In order for the report itself to display localized formats for currencies, dates, etc., make sure you have set the Language property of your report either to default, or to the desired language. This property is initialized to English if you use the English version of Visual Studio.

  • You also have to make sure that the thread is using the correct culture settings. This will default to the setting of your server. You can override it with the language the user has selected in his browser by doing something like

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

    in a suitable place, like the page load or session start.

  • Finally, make sure you use culture aware formatting settings in your report, for example "C" for currencies.


Wednesday, November 09, 2005

Visual Studio Team System not available to partners

On Monday, Microsoft officially launched Visual Studio 2005. There are some new editions of Visual Studio with this release. At the low end, there is the Express edition targeted at the hobbyist developer. The Express edition is available for free.

At the high end is Visual Studio Team System, which comes with several tools, that cover the whole project lifecycle. There are tools for system design, unit testing, web testing, code coverage, profiling, code analysis and so on, all integrated with the development environment. Visual Studio Team System itself comes in four editions, for architects, developers, and testers, which contain only a subset of those tools, and Visual Studio Team Suite, which contains all of them.

Teams that work with Visual Studio Team System can also install a server product, Visual Studio Team System Foundation Server, that integrates all the tools with workflow and source control. The server product will be released next year.

These new products are able to improve the development process considerably, but mind you, there is a learning curve to be mastered here. I have tried to install the beta version of foundation server. It is a bad sign that you need a setup manual to do that. Still, despite using the setup manual, after several hours of installing, my setup just failed with an error number (not even a message). And from what I am reading, configuring the server after installation is no trivial task either.

Realistically, if these new products are supposed to have a good share of the market, Microsoft will have to rely on experts - experts that know how to install and the server, how to configure it for your development process, how to make the most out of the various tools, and how to make sure this thing is used throughout the whole project lifecycle.

Now, I am a Microsoft Certified Partner and Independent Software Vendor, and I have experience with being in charge of a development process and consulting on development processes. So I think I am just the kind of person who could become such an expert and help Microsoft introduce this new product into the market. Surely, Microsoft will leverage their partner infrastructure to do just that?

Apparently, this is not the case. I phoned the partner hotline, and they told me that partners will only have access to the professional edition of Visual Studio. No team foundation server, no tools for architecture, hey, not even unit tests. So I thought the partner hotline must be wrong about this and I contacted my ISV buddy in Redmond. Here is the official statement I received from Microsoft today:

Visual Studio and MSDN Subscriptions are provided by the Microsoft Partner Program as a benefit of MSPP membership.

Prior to the launch of VS2005, MSDN Universal was provided to all members, from Empower through to Certified and Gold Certified members.

As we worked with the Microsoft Partner Program to revise the benefits for Visual Studio 2005, our goal was to provide every partner with a comparable or better benefit than they receive currently. Here is how these benefits have been revised to meet this goal:

  • Partners at the Gold Certified Partner level will receive the enhanced version of Microsoft(r) Visual Studio(r) 2005 Team Edition for Software Developers with MSDN(r) Premium Subscription. As before, this will include 10 MSDN licenses.
  • Partners at the Gold level and in the ISV or Custom Developer Solutions Competency will see an increase of 25 MSDN licenses with the enhanced version of Microsoft(r) Visual Studio(r) 2005 Team Edition for Software Developers with MSDN(r) Premium Subscription
  • Partners at the Certified Partner level will receive the new Microsoft(r) Visual Studio(r) 2005 Professional Edition with MSDN(r) Premium Subscription. As before, this will include 5 MSDN licenses.
  • Empower partners will receive the new Microsoft(r) Visual Studio(r) 2005 Professional Edition with MSDN(r) Premium Subscription. As before, this will include 5 MSDN licenses.

I think this is a very bad decision from Microsoft. Partners like myself will not have the chance to become experts on Visual Studio Team System. Big projects will not be able to introduce Visual Studio Team System without experts. If Microsoft does not rethink this decision, I am afraid that Visual Studio Team System will fail.


Friday, September 16, 2005


I always thought Word and data access were boring. PDC has changed this over night. Julie and Anders blew me away completely. Word and data access are now hot.


Friday, May 27, 2005

Microsoft Certified Partner

I am now a Microsoft Certified Partner with the competency ISV Software Solutions - a true Micro-ISV. To see the logo, look at my business site.