Dataform fields won't appear

Posted by dsetton on Stack Overflow See other posts from Stack Overflow or by dsetton
Published on 2010-01-14T19:46:20Z Indexed on 2010/03/25 0:13 UTC
Read the original article Hit count: 814

Hello!

I am trying to learn how to use the Silverlight 3 DataForm control, because I need to define the DataForm fields myself in the XAML code, that is, I don't want to use the AutoGenerateFields property.

My problem is: the dataform works perfectly when the AutoGenerateFields is set to true, but when I create a DataForm and set the fields manually and run the application, all I get is an empty blank rectangle where my form and its fields should be.

I created a blank Silverligh Navigation Application to test this, and below is the code of the Home.xaml page:

<Grid x:Name="LayoutRoot">

    <StackPanel>

        <!-- This doesn't work. It renders a blank rectangle -->
        <dataFormToolkit:DataForm x:Name="DataForm">
            <dataFormToolkit:DataForm.EditTemplate>
                <DataTemplate>
                    <StackPanel dataFormToolkit:DataField.IsFieldGroup="True">
                        <dataFormToolkit:DataField>
                            <TextBox Text="Test1" />
                        </dataFormToolkit:DataField>
                        <dataFormToolkit:DataField>
                            <TextBox Text="Test2" />
                        </dataFormToolkit:DataField>
                        <dataFormToolkit:DataField>
                            <TextBox Text="Test3" />
                        </dataFormToolkit:DataField>
                    </StackPanel>
                </DataTemplate>
            </dataFormToolkit:DataForm.EditTemplate>
        </dataFormToolkit:DataForm>

        <!-- This works. -->
        <dataFormToolkit:DataForm x:Name="DataForm2"/>

    </StackPanel>

</Grid>

To make the second DataForm work, I simply created a Person class, and put the following in Home.xaml.cs:


protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Person client = new Person { Age = 10, DateOfBirth = new DateTime(1980, 10, 20), FirstName = "John", LastName = "Doe" };
    DataForm2.CurrentItem = client;
}

You can see what happens when I run the application in the following link: http://dl.dropbox.com/u/1946004/image.PNG (I don't have enough points to post images, so...)

Does anyone know what's wrong? Thank you in advance.

© Stack Overflow or respective owner

Related posts about silverlight-3.0

Related posts about DataForm