Validate.BindingForProperty in design mode (WPF integration)

Topics: Validation Application Block
Dec 14, 2010 at 1:26 PM


When I specify for Validate.BindingForProperty attached property on a control in xaml, I get design time exception in both xaml view and design view.

In xaml view I get: The dependency property with name '[the value I provided to BindingForProperty]' for element '[the control]' does not have a binding to validate

In design view I get: An Unhandled Exception has occurred, same error message as in xaml view and this stack trace:

at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WPF.Validate.GetBindingExpressionBaseForPropertyName(FrameworkElement element, String dependencyPropertyName, Boolean thrownOnError)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WPF.Validate.ResetValidatorRule(FrameworkElement element, DependencyPropertyChangedEventArgs args)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WPF.Validate.<>c__DisplayClassa.<ResetValidatorRule>b__1(Object o, EventArgs e)
   at System.Windows.FrameworkElement.RaiseInitialized(EventPrivateKey key, EventArgs e)
   at System.Windows.FrameworkElement.OnInitialized(EventArgs e)
   at System.Windows.FrameworkElement.TryFireInitialized()
   at System.Windows.FrameworkElement.EndInit()
   at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.EndInit(IInstanceBuilderContext context, ViewNode viewNode, DocumentCompositeNode compositeNode, ISupportInitialize supportInitialize)
   at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateProperties(IInstanceBuilderContext context, ViewNode viewNode, DocumentCompositeNode compositeNode)
   at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.Platform.WPF.InstanceBuilders.FrameworkElementInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.Platform.WPF.InstanceBuilders.TextBoxInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at MS.Internal.Services.DesignModeValueProviderService.DesignModeValueProviderBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.DesignModel.Core.ViewNodeManager.Instantiate(ViewNode viewNode)

Is there some way to avoid these errors from happening?

Best Regards,


Dec 15, 2010 at 2:10 AM

Hi Jesper,,

The error you have encountered means that the property value you are validating doesn’t have a binding with the source property. Placing a binding will resolve your problem. It may look something like the code snippet below.

In the .xaml:

<TextBox x:Name="txtName" Height="20" Width="200" Grid.Column="1" Grid.Row="0" TextChanged="validate" Text="{Binding Path=Name , UpdateSourceTrigger=PropertyChanged}" vab:Validate.BindingForProperty="Text">

Business Object’s 'Name' Property:

        [StringLengthValidator(5, MessageTemplate="Name must be less than 5 characters.")]
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }

Hope this helps.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.

Dec 15, 2010 at 9:08 AM

But my control has an binding, my source look like this:

<TextBox Text="{Binding Path=AnnualSalary, TargetNullValue={x:Static sys:String.Empty}}"
               ext:ValidationErrorExtensions.LocalizeExceptionForProperty="Text" />

Where "ext:ValidationErrorExtensions.LocalizeExceptionForProperty" is a custom attached property.


Dec 15, 2010 at 3:10 PM

Hmmm.. have you try to confirm if it still encounter the error without your custom attached property?

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.

Dec 15, 2010 at 3:51 PM

Yes, removing the custom attached property doesn't make any difference.

My solution is running on the Prism framework, but that shouldn't make any difference.

Dec 15, 2010 at 6:58 PM

Let me guess: you're doing this in VS 2010? The validation stuff worked fine in VS 2008, but somewhere late in the 2010 release cycle they changed something in the designer, and it caused these error to come back. We haven't yet been able to figure out how to get the designer to shut up. As far as we know, we're doing everything correctly, and they work perfectly at runtime. It's a little baffling, to be honest.



Dec 16, 2010 at 3:07 PM

Yes, I'm using VS 2010.

I'm very sad to hear that there is no workaround, which could make it possible to use the designer together with the Validation Application Block.