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

Notification

Icon
Error

How to mark required fields in WPF
xomega
#1 Posted : Monday, October 1, 2012 6:19:10 PM(UTC)
xomega



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.
  1. 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>
    
  2. 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>

  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="{x:Static l:EmployeeObject.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.

Copyright © 2009-2022 Xomega.Net. All rights reserved.