How to create a user interface that displays data from an external DataSource using Expression Interactive Designer (“Sparkle“)
- Create a new Visual C# Library project named PersonsDataSource
- Remove Class1 and add both Person and Persons class (described in my previous blog)
- Compile project, you should now have a PersonsDataSource dll.
- Open Sparkle and create a new Project (File ->New Project) name it as you like.
- Now let's add a reference to our PersonsDataSource.dll using Project->Add Item to browse to the previously created assembly.
- You'll now see the dll listed under Project references.
- Open the Data Palette (View->Data) and select Add new CLR DataSource, browse to PersonsDataSource and select Persons item, you should now see Persons listed inside Data palette.
- Select Persons item from Data palette and drag it to Document root surface
- You'll be asked to select how the Persons datasource will be displayed, select ListBox and click Ok.
- The Create Data Template appears: This dialog allows you to 'shape' the DataTemplate associated to Person object, you can select what items and what controls to map to various Person fields (in this case dialog defaults to TextBlocks) leave defaults and click Ok.
- You'll should see the listbox filled with Persons items.
- We now want to add 2 texboxes that will be populated with Listbox selected item.
- Select Library palette and drag two textboxes on DocumentRoot surface.
- Select first texbox and, on Properties palette, click on Text field and select DataBind...
- You'll now see the Create Data Binding dialog, we need to bind to Listbox selected item so click on Element Property and select ListBox.
- Select SelectedItem among ListBox properties.
- Listbox contains instances of Person classes so, select Use custom path expression and type “SelectedItem.Name” (without quotes) on related textbox, then click Ok.
- Do the same with other textbox using “SelectedItem.Age” as custom path expression.
- Press F5 and you'll see that selecting a listbox item selection will be reflected on both textboxes and that changes on textbox contents will be moved to underlying DataSource.