Validation Panel

The panel I’ve been working on to display rich validation messages is slowly coming along. I spent quite a bit of effort over the last two nights making it a well behaved “lookless” control.

The panel itself is simply a class derived from ItemsControl – has no XAML of its own. I then have a Themes/Generic.xaml file that contains the default rendering for the control as follows.

   <Style TargetType="{x:Type local:ValidationPanel}">
        <!-- Default property values -->
        <Setter Property="Background" 
Value="{DynamicResource {x:Static SystemColors.InfoBrushKey}}"/> <Setter Property="BorderBrush"
="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}"/> <Setter Property="BorderThickness" Value="1.5"/> <Setter Property="Margin" Value="2,4"/> <Setter Property="Padding" Value="1"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:ValidationPanel}"> <Border Background="{Binding RelativeSource={RelativeSource TemplatedParent},
=Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="{TemplateBinding Margin}" CornerRadius="2"> <ItemsPresenter Margin="{TemplateBinding Padding}"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate DataType="validation:ValidationContent"> <Grid Margin="4"> <Grid.Resources> <local:SeverityToImageConverter x:Key="imageConverter"/> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Image Source="{Binding Path=Severity,
={StaticResource imageConverter}}"
Stretch="None" Margin="0,0,2,0"/> <TextBlock Text="{Binding Path=MessageText}" Grid.Column="1"/> <TextBlock Text="{Binding Path=MessageDetailText}"
="1" Grid.Row="1" TextWrapping="Wrap"/> </Grid> </DataTemplate> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel/> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>

This displays the panel as shown below which is fairly standard for a message display area.


I then went ahead and created a customised style that changes not just colours but also changes the layout a little. I finally came up with this “vista-ish” look – although its probably a little overdone for real-world use. In this version the secondary text (which in the contrived example is a little redundant) is displayed via a popup invoked by the Help image button.


Now I’m starting on some custom validation rules. One of the things that I want to achieve is to have the rules specify a set of optional commands. These commands will then be used by the Validation Panel to build a context menu (configurable UI of course). Example commands might be focus to control in error, apply default etc.

Since the look of each item in the panel is determined by a DataTemplate which itself is bound to a type – I also want to try creating a derived ValidationContent class so that I can try multiple item UIs within the same panel. This might be useful for example in displaying an “acknowledgement” panel that places the form “in error” until the user has acknowledged the message via a CheckBox. Could be used in scenarios like the typical “I acknowledge that I’ve read your 20 page EULA” message that is often displayed in installers.

6 thoughts on “Validation Panel”

  1. Unfortunately the Validation Panel got well and truly shelved so I don’t have any source code for you . Its still certainly on my list of things to do – but based on the gross inaccuracies of my last prediction I’m not going to guess when exactly I’ll get to it.

  2. Thanks for your reply,
    Actually I worked on one panel but named it FormNotificationPanel and made one wpf adapter for “.Net Validation Framework” (OSS project on codeplex) and may be soon i publish them in one article in CodeProject.

    But,do you allow to also point to your article? and copy some of your xaml code here?


  3. Sure you can point to my posts and copy any of the code fragments/samples. Also thanks for pointing me to the existing validation framework on CodePlex. That certainly looks worth investigating.


Comments are closed.