To bind an enumerable to a control and have them displayed, you can use any of the ItemsControl
and bind your object to the ItemsSource
property. The ItemsControl
s expose a property called ItemsPanel
in which you can further modify to alter the container for the items. StackPanel
is the default in most of them.
<ItemsControl ItemsSource="{Binding NewbieList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!-- The default for an ItemsControl is a StackPanel with a vertical orientation -->
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Edit:
As for your comment, anything within the ItemsSource
will "output" what's in the ItemTemplate
property (the default is basicaly a TextBlock
with the text bound to the DataContext
). For each elements, the DataContext
will be the item in the list. If you have a list of string
, for example, you can do:
<!-- Rest is omitted for succinctness -->
<ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding .}" FontSize="26" MouseDown="yourEventHandler"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl>
Alternatively, if all you want is the font size to change, you can use the TextElement.FontSize
Dependency Property on the ItemsControl
itself or style the ItemsContainer
:
<ItemsControl TextElement.FontSize="26">
<!-- Rest omitted for succinctness -->
</ItemsControl>
Or:
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="TextElement.FontSize" Value="26"/>
</Style>
</ItemsControl.ItemContainerStyle>
I suggest you read articles / tutorials on binding and items control in WPF for more information on how to do various tasks, there is alot to explain.