Compartir a través de


DisplayAttribute.Name Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets either a resource name or non-localized text that is used as a member label for elements that are bound to the member.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

Syntax

'Declaration
Public Property Name As String
public string Name { get; set; }

Property Value

Type: System.String
Either a resource name or the non-localized text that is used as a member label for elements that are bound to the member. The resource name is used with the ResourceType property to retrieve localized text that is used as a member label for elements that are bound to the member.

Remarks

Set the Name property to either a literal non-localized string or to a resource key to use with the ResourceType property to specify a localized name.

Do not use the get accessor of the Name property to retrieve the text to display in your Silverlight application. Instead, use the GetName method to retrieve the name to display. The GetName method returns either the literal non-localized string or the localized string when a resource type has been specified.

Examples

The following example shows how to use the DisplayAttribute attribute to set both localized and non-localized display values. A property named EmailAddress includes non-localized display values and a property named LastName includes localized display values that are retrieved from a resource type named DisplayResources.

Public Class Customer
  <Display(Name:="Email Address", Description:="An email address is needed to provide notifications about the order.")> _
  Public Property EmailAddress() As String
    'Implement Get and Set logic
  End Property

  <Display(ResourceType:=GetType(DisplayResources), Name:="LName", Description:="LNameDescription")> _
  Public Property LastName() As String
    'Implement Get and Set logic
  End Property
End Class
public class Customer
{
  [Display(Name = "Email Address", 
     Description = "An email address is needed to provide notifications about the order.")]
  public string EmailAddress { get; set; }

  [Display(ResourceType=typeof(DisplayResources), Name="LName", Description="LNameDescription")]
  public string LastName { get; set; }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.