Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to mark required fields in Silverlight
xomega
#1 Posted : Monday, October 1, 2012 6:43:41 PM(UTC)
xomega



The following tutorial demonstrates how to set up Silverlight labels, so that their font would be in bold for required fields and in normal weight for optional fields. Unlike WPF, Silverlight doesn't support triggers in styles, which prevents us from using a common style and requires a little more coding. However, it is still possible to use a similar approach to mark required fields in some other way.

The steps to configure the labels to use bold font for required fields in Silverlight are as follows.
  1. Declare a converter from a boolean to FontWeight using the RequiredToFontWeightConverter class declared in the Xomega.Framework.Converters namespace. You can always write your own converter in a similar way to support marking required fields in a different way. Here's an example that demonstrates this step.
    Code:
    <xomc:RequiredToFontWeightConverter x:Key="Required2FontWeight"
          Required="Bold" Optional="Normal"
          xmlns:xomc="clr-namespace:Xomega.Framework.Converters;assembly=Xomega.Framework"/>

  2. On the text block for your label, bind the FontWeight attribute to the xom:Property.Required and use the converter defined in the previous step. The xom prefix should map to the Xomega Framework namespace, e.g. xmlns:xom="clr-namespace:Xomega.Framework;assembly=Xomega.Framework". The following snippet demonstrates this step.
    Code:
    <TextBlock Grid.Row="5" Grid.Column="0" Name="lblBirthDate" Text="Birth Date:"
               FontWeight="{Binding Path=(xom:Property.Required),
                                    RelativeSource={RelativeSource Self},
                                    Converter={StaticResource Required2FontWeight}}"/>

  3. Bind the associated control to a Xomega data property and bind the xom:Property.Label attribute to the label element as follows.
    Code:
    <TextBox Grid.Row="5" Grid.Column="1" Name="ctlBirthDate" xom:Property.Name="BirthDate"
             xom:Property.Label="{Binding ElementName=lblBirthDate}"/>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.