Alignment of label in Dataform
One of the forum users was looking to align the label in the Datafield of DataForm with the following code
<dataFormToolkit:DataField>
<dataFormToolkit:DataField.Label>
<TextBlock Text=”Categories” VerticalAlignment=”Top” />
</dataFormToolkit:DataField.Label>
<Grid>
<StackPanel x:Name=”listCategories” />
</Grid>
</dataFormToolkit:DataField>
sure enough, it doesnt work. I am not sure if there is easier way, but styling the Label does work, changes made to the default style in bold

<Style x:Key=”LabelStyle1″ TargetType=”dataInput:Label”>
<Setter Property=”IsTabStop” Value=”False”/>
<Setter Property=”Template”>
<Setter.Value>
<ControlTemplate TargetType=”dataInput:Label”>
<StackPanel Orientation=”Horizontal”>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name=”CommonStates”>
<VisualState x:Name=”Normal”/>
<VisualState x:Name=”Disabled”/>
</VisualStateGroup>
<VisualStateGroup x:Name=”ValidationStates”>
<VisualState x:Name=”Valid”/>
<VisualState x:Name=”Invalid”/>
</VisualStateGroup>
<VisualStateGroup x:Name=”RequiredStates”>
<VisualState x:Name=”NotRequired”/>
<VisualState x:Name=”Required”>
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration=”0″ Storyboard.TargetName=”ContentControl” Storyboard.TargetProperty=”FontWeight”>
<DiscreteObjectKeyFrame KeyTime=”0″ Value=”SemiBold”/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border Background=”{TemplateBinding Background}” BorderBrush=”{TemplateBinding BorderBrush}”
BorderThickness=”{TemplateBinding BorderThickness}” CornerRadius=”2″ Padding=”{TemplateBinding Padding}” VerticalAlignment=”Top”>
<ContentControl x:Name=”ContentControl” FontFamily=”{TemplateBinding FontFamily}”
FontSize=”{TemplateBinding FontSize}” FontStretch=”{TemplateBinding FontStretch}” FontWeight=”{TemplateBinding FontWeight}”
HorizontalContentAlignment=”{TemplateBinding HorizontalContentAlignment}”
IsTabStop=”False” VerticalContentAlignment=”{TemplateBinding VerticalContentAlignment}”
Cursor=”{TemplateBinding Cursor}” HorizontalAlignment=”{TemplateBinding HorizontalAlignment}”
VerticalAlignment=”{TemplateBinding VerticalAlignment}” Content=”{TemplateBinding Content}”
ContentTemplate=”{TemplateBinding ContentTemplate}” Foreground=”{TemplateBinding Foreground}”/>
</Border>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<dataFormToolkit:DataField LabelStyle=”{StaticResource LabelStyle1}” >
<dataFormToolkit:DataField.Label>
<TextBlock Text=”Categories” />
</dataFormToolkit:DataField.Label>
<Grid>
<StackPanel x:Name=”listCategories”>
<CheckBox Content=”Checkbox1″/>
<CheckBox Content=”Checkbox2″/>
<CheckBox Content=”Checkbox3″/>
<CheckBox Content=”Checkbox4″/>
<CheckBox Content=”Checkbox5″/>
</StackPanel>
</Grid>
</dataFormToolkit:DataField>
Hi Lee,
I’m trying to set the Margin to 0 for the DataField in a style. I’ve tried this but it doesn’t work. Any idea on what I’m doing wrong?
…