Search code examples
.netsilverlightdataform

Silverlight DataForm control with RIA ( i.e. Display(Description=....)]


I want the change the description of the labels on my silverlight dataform which currently show as my table fieldnames (dbEmailAddress).

<StackPanel Grid.Row="0" Grid.Column="1">
            <dataFormToolkit:DataForm x:Name="dataForm1"
                                      CurrentItem="{Binding SelectedItem, ElementName=dgLeagues}"
                                      Header="Product Details"
                                      >

        </dataFormToolkit:DataForm>

I know I can get around this by adding DataFields programmatically in the xaml, but is there away to add the attributes in the RIA class ( in the web application) so it filters through, something like this in the ria domain metadata file.

[Display(Name = "Email Address:", 
Description="We do not sell your information!")]
public string EmailAddress { get; set; }

-would this work?

Also if it would, then would this approach be useless as a recompile of the ria domain service metadata file mean I would loose any changes since its generated?

Thanks, jason


Solution

  • What you have done is actually fine. To avoid redoing it every time you recompile, you can add it to your metadata.

    [Display(Name = "Email Address:", 
             Description="We do not sell your information!")]
    public string EmailAddress = null;
    

    When you create your DomainService you can add a related metadata class - if you haven't that you can easily create it manually. The metadata class is designed to hold the exact information you describe.

    [MetadataType(typeof(CustomerMetadata))]
    public partial class Customer 
    {
        private static class CustomerMetadata 
        {
            [Required]
            [Display(Name = "Email Address:",
                     Description = "We do not sell your information!")]
            public string EmailAddress = null;
        }
    }
    

    Remember to name the metadata file customer.metadata.cs or whatever your class is called. It's imported to postfix with *.metadata.cs. It's a good idea to put your metadata file in the same folder as your DomainService.