Condividi tramite


Generate sample data

You can use the tools in the Data panel of Blend for Visual Studio 2012 to generate sample data for your application. Sample data is useful when you are designing the appearance of controls that will display live data that you might not have access to at design time.

In addition to being able to generate sample data based on a schema you define manually, you can also generate sample data based on a class. When you create sample data from a class, the data is available in the form of a XAML file, and stored in the SampleData folder.

To generate sample data

  1. To enable the sample data tools, open a XAML document on the artboard in Design view JJ170225.32be2832-9f81-4617-97e6-a4a3988a136c(it-it,VS.110).png or Split view JJ170225.5b79e600-984e-4f44-b8cd-6c1522832ad4(it-it,VS.110).png.

  2. If you do not see the Data panel, make sure that a check mark appears next to Data on the Window menu.

    For more information, see Add or remove a workspace panel.

  3. In the Data panel, click Create sample data JJ170225.30540d76-7256-43ce-b5d9-4b2edf3d339f(it-it,VS.110).png, and then click New Sample Data.

  4. In the New Sample Data dialog box, type a descriptive name for your data source in the Data source name field.

  5. Under Create data source in, select one of the following:

    • Project   Use this option to make the data available to all documents in the project.

    • This document   Use this option to make the data available only to the currently-open XAML document.

  6. If you want your application to be able to display sample data when you run it (F5), make sure Enable sample data when application is running is selected. If this option is not selected, you will be able to see sample data only on the artboard, and not in your application window at run-time.

  7. Click OK to close the New Sample Data dialog box and create the sample data.

    In the Projects panel, in a folder named SampleData, a subfolder is added for your new sample data source. It contains the files required to define the data.

    In the Data panel, you can expand the nodes of your new data source to view the schema of your sample data. An initial collection of strings and boolean properties was generated by Blend.

    JJ170225.496d7ebc-fe46-42f6-95a8-57b0e5be5d49(it-it,VS.110).png

    [!NOTA]

    The Data panel shows you the structure (or schema) of your data, not the data itself. For example, in the Data panel, you will see a Collection node, under which you will see a string property (Property1), meaning that your data consists of a collection of records where each record contains a string. To view the actual data that was generated, click Edit sample values JJ170225.05e097fd-b5b7-4a06-b97a-bf7ece17b6c6(it-it,VS.110).png next to the Collection node JJ170225.B4_Data_CollectionIdentifier(it-it,VS.110).png.

    You can now drag the Collection node onto the artboard to create a list box, or onto an existing object, such as a DataGrid object, to display the data.

    List of items created by dragging the initial generated collection onto the artboard

    JJ170225.23ff15ed-b181-417f-b57f-9605d96312ea(it-it,VS.110).png
    List of items after dragging the initial generated collection onto a DataGrid object

    JJ170225.917dd79d-8fe8-4e82-970b-55c9705a5e3e(it-it,VS.110).png

    You can also modify the sample data, adding properties and changing values.

    For more information, see Modify sample data.

Vedere anche

Attività

Modify sample data

Import sample data from an XML file

Altre risorse

Displaying data in controls