tags:

views:

278

answers:

2

I'd like to know if there is a Silverlight control that allows me to display a list of items horizontally with a separator between each pair of items.

For example, suppose this is my list of items:

int[] items = new[] { 42, 43, 44, 45 };

then I want them to be rendered like this:

42 -> 43 -> 44 -> 45

This is just an example, in reality the items are objects that I'd like to bind to a template and the separator should be an image (or anything else). And in my case, the items are rendered as an element inside an ItemsControl.

Seems rather simple, but I can't find a good way to do this.

Kind regards, Ronald

+1  A: 

You could use a StackPanel with horizontal orientation, and add sequences of number (in a TextBox control) + separator (as an Image control) as you need it.

Konamiman
I was actually hoping there would be a standard control that I could use for this, but I suppose such a control does not exist?
Ronald Wildenberg
None that I know about, but anyway implementing a solution based on StackPanel is really easy, see the answer from Erez.
Konamiman
The problem is that the rendering of my items happens inside a DataTemplate inside an ItemsControl. So I wouldn't know when to add my items to the StackPanel.
Ronald Wildenberg
+1  A: 

This worked fine for me:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="333" Width="454">
    <Window.Resources>
    </Window.Resources>
    <StackPanel Name="myStackPanel">
    </StackPanel>
</Window>

and the Code Behind:

     int[] items = new[] { 42, 43, 44, 45 };

        myStackPanel.Orientation = Orientation.Horizontal;

        foreach (int item in items)
        {
            TextBlock txtNum = new TextBlock();
            txtNum.Text = item.ToString();

            TextBlock txtSeperator = new TextBlock(); // or image, as you wish
            txtSeperator.Text = "->";

            myStackPanel.Children.Add(txtNum);
            myStackPanel.Children.Add(txtSeperator);
        }
Erez
But what if I do not want a TextBlock to render my items but a custom template. Is this possible somehow?
Ronald Wildenberg