The following tutorial demonstrates how to set up WPF labels, so that their font would be in bold for required fields and in normal weight for optional fields. It will utilize the WPF styles for labels to allow controlling it in one place. You can use a similar approach to implement a different way of marking the required labels.
The steps to configure the labels to use bold font for required fields are as follows.
- Set up a style for all labels in your application resources. Add a trigger for the xom:Property.Required property, which sets the FontWeight to Bold. 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:
<Style x:Key="LabelStyle" TargetType="{x:Type Label}">
<Style.Triggers>
<Trigger Property="xom:Property.Required" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</Style.Triggers>
</Style>
- Set this style on your label elements as follows.
Code:
<Label Name="lblBirthDate" Style="{StaticResource LabelStyle}"
Grid.Row="5" Grid.Column="0">_Birth Date:</Label>
- 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="{x:Static l:EmployeeObject.BirthDate}"
xom:Property.Label="{Binding ElementName=lblBirthDate}"/>