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 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.
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 Blend or by importing an XML file.
To add items to your sample data
In the Data panel, expand the sample data source, and then locate the node to which you want to add more properties.
Dica 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.
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.
Dica 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.
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
Remove items from your sample data
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.
Change the type of a simple property
To change the type of a simple property
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 .
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.
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.
To change the data that will be generated for a simple property
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 .
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
Dica 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.
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.
To rename data properties (or column headers)
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.
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.
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.
To manually change sample data values
In the Data panel, expand the sample data source, locate the collection whose data you want to change, and then click Edit sample values .
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.
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.
To create a recursive tree of data
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.
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.
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.
Observação Blend will create a new ItemTemplate. However, Blend does not delete the previous ItemTemplate associated with the Listbox.
To update a DataGrid object after changing the data structure
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.
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.
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.
Consulte também
Tarefas
Import sample data from an XML file