A more general approach than the suggestion of Julien Leboscan (and the one that will work when the list of elements contains objects of more than one data type):
Create a DataTemplate that will be used when representing the element of type (s) in your list, for example:
<DataTemplate DataType="local:Measure"> <local:MeasureUserControl DataContext="{Binding}"/> </DataTemplate>
Use ItemsControl to represent items:
<ItemsControl ItemsSource="{Binding MeasureList}"/>
You can set the ItemsPanel ItemsControl property to ItemsPanelTemplate to determine how it will expose user controls, for example:
<ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel>
This approach is usually preferable to using a ListBox if you do not want to use the ListBox functions, for example. its default boundaries and selection behavior.
source share