Share via


Modify sample data (Windows Phone)

You can modify the structure (or schema) and the values of any sample data source. Sample data is stored in subfolders in the SampleData project folder, whether the sample data was generated for you by Blend for Visual Studio 2012 or imported from an XML file. Any modifications that you make in the Data panel are recorded in the files in the SampleData folder. This means that if you import an XML file, you can use the following procedures to modify the data in your project without affecting the original XML file.

To modify the schema of your sample data, you can add more properties either to the initial set that is generated by Blend or by importing an XML file.

To add items to your sample data

  1. In the Data panel, expand the sample data source, and then locate the node to which you want to add more properties.

Tip

You can add properties to the root of the data source, to a collection property, or to a complex property. A plus sign appears next to any node to which you can add properties.

  1. Click the arrow next to the plus sign , and then, on the drop-down menu that appears, click one of the following options:

    • Add Simple Property   Use this option to add a String, Number, Boolean, or Image property. By default, a String property is added, but after you create the property, you can click Change property type  to select a different type.

    • Add Complex Property   Use this option to create a property that can contain child properties. For example, RSS feeds often represent a channel using a complex property whose child properties include the category, description, and a collection of news items related to the channel.

    • Add Collection Property   Use this option to create a collection of records where each record can contain multiple items of data. For example, RSS feeds often represent news items in a collection where each record in the collection includes the title of the news item, the description, and other related information.

Tip

You can nest collections to create a tree of data. Alternatively, you can convert an existing collection property to a tree. For more information, see "To create a recursive tree of data" in Modify sample data.

  1. The new data item appears with the name field editable. If you want to change the name, type a different name and press ENTER.

    After adding a string property to an existing collection

To add items to your sample data

  1. In the Data panel, expand the sample data source, and then locate the node to which you want to add more properties.

Tip

You can add properties to the root of the data source, to a collection property, or to a complex property. A plus sign appears next to any node to which you can add properties.

  1. Click the arrow next to the plus sign , and then, on the drop-down menu that appears, click one of the following options:

    • Add Simple Property   Use this option to add a String, Number, Boolean, or Image property. By default, a String property is added, but after you create the property, you can click Change property type  to select a different type.

    • Add Complex Property   Use this option to create a property that can contain child properties. For example, RSS feeds often represent a channel using a complex property whose child properties include the category, description, and a collection of news items related to the channel.

    • Add Collection Property   Use this option to create a collection of records where each record can contain multiple items of data. For example, RSS feeds often represent news items in a collection where each record in the collection includes the title of the news item, the description, and other related information.

Tip

You can nest collections to create a tree of data. Alternatively, you can convert an existing collection property to a tree. For more information, see "To create a recursive tree of data" in Modify sample data.

  1. The new data item appears with the name field editable. If you want to change the name, type a different name and press ENTER.

    After adding a string property to an existing collection

To remove items from your sample data

  • In the Data panel, expand the sample data source, right-click the property that you want to remove, and then click Remove "Item_name".

    If the property was already bound to an object on the artboard, the data will no longer appear in the object.

To change the type of a simple property

  1. In the Data panel, expand the sample data source, locate the simple property whose type you want to change, and then click Change property type .

  2. In the pop-up menu that appears, click the drop-down arrow next to Type, and then select the data type that you want: String, Number, Boolean, or Image.

    The type of the property is changed and new sample data is generated.

To change the data that will be generated for a simple property

Some types of simple properties (String, Number, or Image) provide a custom editor so that you can change aspects of the data that is generated by Blend. For example, you can specify that generated numbers should be three digits long instead of two, or you can specify that generated images should come from a specific folder.

  1. In the Data panel, expand the sample data source, locate the property whose generated data you want to change, and then click Change property type .

  2. In the pop-up menu that appears, modify the fields that appear underneath the Type field.

    New sample data is instantly generated. If the data is already displayed in an object on the artboard, the object is immediately updated with the new data.

    Changing a string property to generate phone numbers instead of random text

    Changing an image property to use images from a specific folder instead of the default chair images

Tip

If you change an image data property by specifying a folder from which Blend will get sample images, the image files in that folder will be copied into a subfolder of the data source folder in the SampleData project folder.

To manually change sample data values

You can manually change data by editing the collection that contains the data. You can change both generated data and data that was imported from an XML file because both forms of sample data are stored in the files of the SampleData project folder.

  1. In the Data panel, expand the sample data source, locate the collection whose data you want to change, and then click Edit sample values .

  2. In the Edit Sample Values dialog box, modify the generated data, the number of records generated, or the type of data represented in the column. For example, double-click an image to select a different image file.

    If the data is already displayed in an object on the artboard, the object is immediately updated to display the newly generated data.

To create a recursive tree of data

By default, when a collection property is generated, a flat collection of data is created. You can use a flat collection in data controls such as the ListBox. However, you might want to generate a tree of hierarchical data that can be displayed in controls such as a ListBox control.

  1. In the Data panel, expand the sample data source, locate the collection whose structure you want to change from flat to hierarchical, click the arrow next to the plus sign , and then, from the drop-down menu that appears, click Convert to Hierarchical Collection.

    When a flat collection is converted to nested collections, the collection provides properties that are nested five levels deep. The name of the second-level collection becomes editable.

  2. Type a descriptive name, and then press ENTER.

    You can now drag the collection onto a ListBox object or other hierarchical object to display the data.

To update an object after changing data

If you modify the values of sample data items that are displayed in an object on the artboard, the object is automatically updated to display the new values.

However, if you add or delete properties in a collection of data, or change the type of a data property, the displaying object will not be updated because those changes modify the structure (or schema) of the data. When you change the structure of displayed data, you have to create the bindings again.

To update a ListBox object after changing the data structure

  • From the Data panel, drag the items that you want to display onto the ListBox object.

Note

Blend will create a new ItemTemplate. However, Blend does not delete the previous ItemTemplate associated with the Listbox.

See Also

Tasks

Generate sample data

Import sample data from an XML file (Windows Phone)