Modify sample data

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 Microsoft Expression Blend 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 add items to your sample data

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

  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 Ee341407.203a14a5-0db2-486e-9b94-4fdf658d531b(en-us,Expression.40).png appears next to any node to which you can add properties.

  2. Click the arrow next to the plus sign Ee341407.203a14a5-0db2-486e-9b94-4fdf658d531b(en-us,Expression.40).png, 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 Ee341407.c4968582-0dae-407e-961b-80ffa2838f3b(en-us,Expression.40).png 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.

  3. 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

    Ee341407.b96caa7b-b699-4012-bdb4-bf3160ebb941(en-us,Expression.40).png

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 Ee341407.c4968582-0dae-407e-961b-80ffa2838f3b(en-us,Expression.40).png.

  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.

    Ee341407.f775d060-157f-4a8d-9e1a-168e94e49551(en-us,Expression.40).png

    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 Expression 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 Ee341407.c4968582-0dae-407e-961b-80ffa2838f3b(en-us,Expression.40).png.

  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

    Ee341407.8b1307aa-8568-4a9c-a547-e25d9ac73013(en-us,Expression.40).png

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

    Ee341407.f62d8ae8-6655-481c-bf93-243efd5e0aa2(en-us,Expression.40).png

    Tip

    If you change an image data property by specifying a folder from which Expression 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.

    Ee341407.7448033e-c71e-44a6-bc0e-17d55018390d(en-us,Expression.40).png

To rename data properties (or column headers)

When you drag collections onto controls such as the DataGrid control, the property names in the schema are used to label the column headers on the artboard. You can change the names of schema properties in the Data panel, but if the data is already displayed in a DataGrid object on the artboard, you will have to change the Header properties of the columns.

  1. In the Data panel, expand the sample data source, locate the property whose name you want to change, and then double-click the name to make it editable. Type a new name and press ENTER.

    Existing data bindings are updated to use the new property name.

  2. If the data was used in a column of a DataGrid object on the artboard, expand the DataGrid object that displays the collection in the Objects and Timeline panel, expand the Columns object, and then select the column whose name you want to change. In the Properties panel, locate the Header property, type a new name, and then press ENTER.

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 Ee341407.05e097fd-b5b7-4a06-b97a-bf7ece17b6c6(en-us,Expression.40).png.

    Ee341407.8951281b-fc87-4fe1-b6fc-e9717a26667b(en-us,Expression.40).png

  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.

    Ee341407.c752919c-2d0e-49d1-b4dd-73d53baee147(en-us,Expression.40).png

    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 and DataGrid controls. However, you might want to generate a tree of hierarchical data that can be displayed in controls such as a TreeView 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 Ee341407.203a14a5-0db2-486e-9b94-4fdf658d531b(en-us,Expression.40).png, 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 TreeView 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

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

To update a DataGrid object after changing the data structure

  1. In the Objects and Timeline panel, expand the Columns node under the DataGrid object, and then delete the column that corresponds to the updated data.

  2. Drag the modified collection property that you want to display from the Data panel onto the DataGrid object.

    A new column is added to the end of the DataGrid object, and displays the data in the property.

  3. If you want to reorder the columns in the DataGrid object, drag the columns to different locations under the Columns node in the Objects and Timeline panel.

See also

Tasks

Generate sample data
Import sample data from an XML file

Other resources

Displaying data in controls

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.