Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:25:58+00:00 2026-06-04T02:25:58+00:00

There is a problem in .NET 4.0, which does not exist in 3.5 (have

  • 0

There is a problem in .NET 4.0, which does not exist in 3.5 (have not tested earlier or later frameworks).

I have created a demo user control, which has only a single property Num (of type Integer):

Public Class UserControl1

Public Shared NumProperty As DependencyProperty = _
            DependencyProperty.Register("Num", _
                                        GetType(Integer), _
                                        GetType(UserControl1), _
                                        New PropertyMetadata(defaultValue:=0, _
                                                PropertyChangedCallback:=New PropertyChangedCallback(AddressOf OnNumPropertyChanged), _
                                                CoerceValueCallback:=New CoerceValueCallback(AddressOf OnNumPorpertyCoerce)), _
                                        New ValidateValueCallback(AddressOf IsNumValid))

Public Property Num As Integer
    Get
        Return GetValue(NumProperty)
    End Get
    Set(value As Integer)
        SetValue(NumProperty, value)
    End Set
End Property

Public Shared Function IsNumValid(value As Object) As Boolean
    If value IsNot Nothing And TypeOf value Is Integer Then
        If CInt(value) < 0 Then
            Return False
        End If
    End If

    Return True
End Function

Public Shared Sub OnNumPropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
    ' do nothing here
End Sub

End Class

So, basically, you can not set anything smaller than zero to Num.

The question

When I use this control in WPF window and try to set Num=-1, I get the exception.
However if I try to use this control as part of DataTemplate, and also set Num=-1, there is no excepetion raised.

I have tried to put a breakpoint in Validation procedure of my user control, but it is hit only in case of user control in window, and it is not hit if I have user control in DataTemplate.

Can anybody explain why validation is not executed from DataTemplate?

P.S. you can find related thread on Microsoft’s forums: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f7fd05a5-cae3-496a-8abe-590541ecdd0a

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:26:00+00:00Added an answer on June 4, 2026 at 2:26 am

    While Microsoft solves this problem (upvote at https://connect.microsoft.com/VisualStudio/feedback/details/742083/dependencyproperty-validation-is-not-called-from-data-template), workaround may be used:

    In your coercion function call validation function (leave validation function for all those cases then it is called). And if the validation result is False, raise an System.ArgumentException with a message of such pattern: ‘%INVALID VALUE%’ is not a valid value for property ‘%PROPERTY_NAME%’. By providing such code you will provide user of your user control with same information he or she would get from regular validation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is in my navigation bar, which can be found here: http://grupocoral.netai.net/ There
http://jsfiddle.net/q8P7Y/ I have a problem of showing the final score at the end, there
Problem: There are a lot of different databases, which is populated by many different
HI, I have a .NET application which uses threads excessively. At the time of
I have created an ASP.net application with several aspx. Some of them are used
I have an asp.net dropDownList which is automatically bound to a sqlDataSource to values
I have a .NET 3.5 web application for which I have implemented a class
I have written an ASP.NET web application (not site) in Delphi Prism. Everything works
As part of a CMS, I have created a custom VirtualPathProvider which is designed
Made an application which targets .net 4 client. Created an installer using Inno Setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.