Item Selection
User interfaces often display a list of items to a user in a
control such as a ListBox and allow
the user to select one of the items. Once he makes the selection, the
user may be brought to another screen, another control may appear with
detailed information about the selected item, or the selected item’s
details may appear in a series of controls below the ListBox. Generally, this is a good design
practice, as it is often impossible to effectively display all of the
information about an item in a list-based control. For example, if an
entity such as a Product has more
than 50 properties, displaying all of those properties in a list-based
control would be problematic and likely would not be very user-friendly.
Though with Silverlight 2 and XAML, you can alleviate this somewhat by
creating a DataTemplate that contains
several rows of information within each row of the ListBox. However, even this solution has its
limits.
One possible solution to this type of problem is to display a list
of items that contains a summary of the items in a control such as a
ListBox. Then when the user selects
an item from the ListBox, the details
of all of the properties for the Product are displayed in a series of controls.
The code in Example 4-7
shows how to implement this type of scenario.
Example 4-7. Setting the DataContext for the selected product
C# private void lstProducts_SelectionChanged(object sender, SelectionChangedEventArgs e) { Product product = (Product) lstProducts.SelectedItem; ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access