Using ItemsControl in combination with some kind of panel seems to be the cleanest solution for me. (As already mentioned, UniformGrid may be a good choice), for example:
<ItemsControl> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="FrameworkElement.Margin" Value="5"/> </Style> </ItemsControl.ItemContainerStyle> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Rows="1"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.Items> <Button Content="Button"/> <Button Content="Button"/> <Button Content="Button"/> <Button Content="Button"/> </ItemsControl.Items> </ItemsControl>
This has the advantage that the interval layout is handled by the element control rather than manually applied to the content. The content can then be any element of the FrameworkElement, and the span will still apply.
source share