Using the Silverlight HeaderedContentControl
page 4 of 5
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 26870/ 69

Items Binding

So what if you want multiple items within the Header/Content?  You could use an ItemsControl, like the HeaderedItemsControl class.  This control already provides this ability with ease.  However, using the HeaderedContentControl, the solution can also be to use an ItemsControl within the content.  To setup this example, suppose you had the following:

Listing 5: Example Class

public class SampleClass
{
      public string Title { get; set; }
      public string Text { get; set; }
      public List<SampleItem> Items { get; set; }
}
Public class SampleItem
{
      public string Name { get; set; }
      public string Value { get; set; }
}

Using a similar setup previously for the header/content, the solution to binding a repetitive list within the HeaderedContentControl control is to use a repetitive control (like the ListBox control) within the content.

<HeaderedContentControl Header="{Binding Title}">
      <HeaderedContentControl.Content>
            <ListBox ItemsSource="{Binding Items}">
                  <ListBox.ItemTemplate>
                        <DataTemplate>
                              <StackPanel>
                                    <Label Content="{Binding Name}" />
                                    <Label Content="{Binding Value}" />
                              </StackPanel>
                        </DataTemplate>
                  </ListBox.ItemTemplate>
            </ListBox>
      </HeaderedContentControl.Content>
</HeaderedContentControl>

In this example, the ListBox control is a way to show multiple items within the content.  The source of the content comes from the Items property in the SampleClass class.  Any items in this list is bound to the ListBox, which each item gets its own instance of the provided DataTemplate, binding each SampleItem object to the created template for the ListBoxItem.


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-18 1:33:21 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search