Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight ValidationSummary omits MessageHeader for Property bound by UserControl
    primarykey
    data
    text
    <p>I’ve defined a custom UserControl with DependencyProperty. My page contains the UserControl, a Textbox, and a ValidationSummary. Using XAML, the page instantiates the Textbox and UserControl, binding their DependencyProperties to Properties of a single ViewModel. The ValidationSummary works as expected for the "Request Description" Textbox:</p> <ol> <li>MessageHeader (bolded) shows text from bound property’s DisplayAttribute’s Name property. </li> <li><p>Message (non-bolded) shows text of exception thrown by bound property.</p> <pre><code>&lt;Display(Name:="Request Description")&gt; _ Public Property RequestDescription() As String Get … End Get Set(ByVal value As String) … If value.ToLower.Contains("zombie") Then Throw New Exception("We're not saying the zed word.") End If … End Set End Property </code></pre></li> </ol> <p>However, the ValidationSummary for the "Fleet Unit" UserControl lacks a MessageHeader.</p> <p><img src="https://imgur.com/3hMNO.png" alt="val sum"></p> <p>When I examine the ValidationSummary’s errors property, I find that the error for the UserControl has:</p> <ul> <li>MessageHeader=Nothing</li> <li>Sources.Count=1</li> <li>Sources(0).Control=MyUserControl</li> <li>Sources(0).PropertyName=Nothing</li> </ul> <p>In contrast, the error for the Textbox has both MessageHeader and Sources(0).PropertyName matching the DisplayAttribute’s Name property.</p> <p>I’ve placed a DisplayAttribute with Name on the ViewModel property to which the UserControl is bound. I’ve tried placing DisplaceAttributes in the UserControl’s DependencyProperty as well as the Property named in the DependencyProperty’s registration. None of these flow through to the ValidationSummary’s ValidationSummaryItemSource.PropertyName.</p> <p>Can anyone offer a tip on making ValidationSummary show a MessageHeader for a property bound by a UserControl?</p> <p>More info (11/2/2011 5:15 PM ET):<br> Clicking on either of the errors listed in ValidationSummary causes the related control to be focused. When the Textbox is clicked, the Message is displayed to the right of the Textbox as well as in the ValidationSummary. (Not shown.) When the UserControl is clicked the Message only appears in the ValidationSummary.</p> <p>More info (11/9/2011 10:14 AM ET):<br> kmacmahon: Hopefully this what you needed. Thanks for your help!</p> <pre><code>Function ValidateEntry(ByVal fieldname As String, ByRef value As Object) _ As Object Dim ctx As New ValidationContext(Me, Nothing, Nothing) ctx.MemberName = fieldname Validator.ValidateProperty(value, ctx) Return value End Function </code></pre> <p>.</p> <pre><code>&lt;Display(Name:="Fleet Unit ID")&gt; _ &lt;Required(ErrorMessage:="Fleet Unit is required, but not supplied.")&gt; _ Public Property FleetUnitID As Integer? Get Return _Incident.EFleetUnitID End Get Set(ByVal value As Integer?) Const propname As String = "FleetUnitID" If Not Equals(_Incident.EFleetUnitID, value) Then If value Is Nothing Then _Incident.EFleetUnitID = Nothing Else _Incident.EFleetUnitID = ValidateEntry(propname, value) End If NotifyChangeUpdate(propname) ElseIf value Is Nothing AndAlso FleetUnitIDRequired Then ValidateEntry(propname, value) End If End Set End Property </code></pre> <p>.</p> <pre><code>&lt;Display(Name:="Request Description")&gt; _ &lt;Required(ErrorMessage:="Please describe your request.")&gt; _ &lt;StringLength(8000)&gt; _ Public Property RequestDescription() As String Get Return Incident.RequestDescription End Get Set(ByVal value As String) Const propname As String = "RequestDescription" If Not Equals(Incident.RequestDescription, value) Then Incident.RequestDescription = ValidateEntry(propname, value) NotifyChangeUpdate(propname) End If If RequestSpecificReference IsNot Nothing _ AndAlso RequestSpecificReference.Template &gt; "" Then If value = RequestSpecificReference.Template Then Throw New Exception("Please provide information" _ &amp; " requested in description field.") End If End If If value.ToLower.Contains("zombie") Then Throw New Exception("We're not saying the zed word.") End If NotifyPropertyChanged("SubmitButtonVisibility") End Set End Property </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload