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 do not want to use the AutoGenerateFields property.
My problem is that the data form works fine when AutoGenerateFields is set to true, but when I create the DataForm and manually set the fields and run the application, all I get is an empty empty rectangle where my form should be and her fields.
I created an empty Silverligh Navigation application to test it, and below is the code for the Home.xaml page:
<Grid x:Name="LayoutRoot">
<StackPanel>
<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>
<dataFormToolkit:DataForm x:Name="DataForm2"/>
</StackPanel>
</Grid>
Code>
To make the second DataForm work, I simply created the Person class and placed 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:
Does anyone know what happened? Thank you in advance.
source
share