Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding Silverlight 3 description attribute of dataInput:DescriptionViewer
    primarykey
    data
    text
    <p>Silverlight's <strong>dataInput:Label</strong> and <strong>dataInput:DescriptionViewer</strong> controls provide a useful function through their ability to bind to a TextBox. Rather than hard-coding the text content of my labels and descriptions with System.ComponentModel.DataAnnotations.DisplayAttribute, I'd prefer to bind these attributes to properties of a class that holds admin-editable text. This works for Label, but not for DescriptionViewer. </p> <p>Specifically, this Label works:</p> <pre><code>&lt;dataInput:Label Grid.Row="00" Grid.Column="0" Target="{Binding ElementName=inpStatus}" Content="{Binding StatusLabel}" IsRequired="true" /&gt; </code></pre> <p>but this DescriptionViewer is invisible:</p> <pre><code>&lt;dataInput:DescriptionViewer Grid.Row="00" Grid.Column="3" Target="{Binding ElementName=inpStatus}" Name="dvBound2" Description="{Binding Path=StatusDescription}" /&gt; </code></pre> <p>When I remove the binding to my TextBox, the DescriptionViewer is shown:</p> <pre><code>&lt;dataInput:DescriptionViewer Grid.Row="00" Grid.Column="2" Name="dvBound1" Description="{Binding Path=StatusDescription}" /&gt; </code></pre> <p>Should it be possible to bind a DescriptionViewer to both a TextBox and an alternate Description source? </p> <p>Thanks in advance! </p> <p>MainPage.xaml:</p> <pre><code>&lt;UserControl x:Class="DataInputDemo.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"&gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="142"&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition Width="100"/&gt; &lt;ColumnDefinition Width="24"&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition Width="24"&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="30"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="30"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;dataInput:Label Grid.Row="00" Grid.Column="0" Target="{Binding ElementName=inpStatus}" Content="{Binding StatusLabel}" IsRequired="true" /&gt; &lt;TextBox Grid.Row="00" Grid.Column="1" Text="{Binding Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, Path=Status}" Name="inpStatus" MaxLength="025" BindingValidationError="_BindingValidationError" /&gt; &lt;dataInput:DescriptionViewer Grid.Row="00" Grid.Column="2" Name="dvBound1" Description="{Binding Path=StatusDescription}" /&gt; &lt;!-- Following DescriptionViewer is not shown. --&gt; &lt;dataInput:DescriptionViewer Grid.Row="00" Grid.Column="3" Target="{Binding ElementName=inpStatus}" Name="dvBound2" Description="{Binding Path=StatusDescription}" /&gt; &lt;dataInput:ValidationSummary Grid.Row="01" Grid.Column="0" Grid.ColumnSpan="4" Name="VS1" /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>MainPage.xaml.vb:</p> <pre><code>Partial Public Class MainPage Inherits UserControl Public myDataClass = New DataClass Public Sub New() InitializeComponent() myDataClass.status = "Default Status" myDataClass.StatusLabel = "Status Label" myDataClass.StatusDescription = "Status Description" LayoutRoot.DataContext = myDataClass End Sub Private Sub _BindingValidationError(ByVal sender As Object, ByVal e As ValidationErrorEventArgs) End Sub End Class </code></pre> <p>DataClass.vb:</p> <pre><code>Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.Runtime.Serialization Imports System.ComponentModel.DataAnnotations Imports System.Windows.Controls Public Class DataClass Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler _ Implements INotifyPropertyChanged.PropertyChanged Private Sub NotifyPropertyChanged(ByVal info As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info)) End Sub 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 &lt;DataMember()&gt; _ &lt;Required()&gt; _ &lt;StringLength(100)&gt; _ Public Property Status() As String Get Return _Status End Get Set(ByVal value As String) _Status = ValidateEntry("Status", value) NotifyPropertyChanged("") End Set End Property Private _Status As String &lt;DataMember()&gt; _ Public Property StatusLabel() As String Get Return _StatusLabel End Get Set(ByVal value As String) _StatusLabel = value NotifyPropertyChanged("") End Set End Property Private _StatusLabel As String &lt;DataMember()&gt; _ Public Property StatusDescription() As String Get Return _StatusDescription End Get Set(ByVal value As String) _StatusDescription = value NotifyPropertyChanged("") End Set End Property Private _StatusDescription As String End Class </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