views:

173

answers:

1

How do I change the spacing between fields in a DataForm in Silverlight?

I've tried editing the template but cannot find what I need. I thought all I needed to do was change the MinHeight and Margin of the DataField style, but that doesn't seem to do it.

<Style TargetType="dataFormToolkit:DataField">
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Margin" Value="2"/>
        <Setter Property="MinHeight" Value="5"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="dataFormToolkit:DataField">
                    <ContentControl x:Name="ContentControl" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="Stretch" IsTabStop="False" VerticalAlignment="Center"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I've found a number of articles about styling DataForm but many of them seem to be out of date. I don't see anything in the complete extracted template in Blend that corresponds to spacing.

+1  A: 

Well changing the Margin on the style does change the spacing.

I'm gonna guess that you have the above style in a resource and are expecting it to apply implicitly to all DataField instances. Silverlight 3 does not have support for implicit styles (the toolkit has some attached properties which can provide some semblence of implicit styles though).

You need to reference this style from the DataForm:-

<Grid.Resources>
  <Style x:Key="DataFieldStyle" TargetType="dataFormToolkit:DataField">
    <Setter Property="Margin" Value="2"/>
    <Setter Property="MinHeight" Value="5"/>
  </Style>
</Grid.Resources>
<DataForm DataFieldStyle="{StaticResource DataFieldStyle}" />
AnthonyWJones
i'm actually using Silverlight 4 which does implicitly apply styles. The key thing here was applying the DataField style to the DataForm itself. Even if you apply it to every DataField in the form it doesn't take effect. As soon as i assigned it to the DataForm itself it worked. Thanks!
Simon_Weaver