DataTemplateSelector with StackPanel Horizontal Orientation ?

Topics: Prism v4 - Silverlight 4
Sep 1, 2011 at 3:47 PM

I am using this XAML to have a variable number of "Products" displayed, but realized that if I switch the StackPanel Orientation from Vertical to Horizontal, this has no effect, all the "Products" are still added vertically.

Is there anyway to have it working horizontally?

Thanks for your help


<StackPanel Orientation="Horizontal">

                    <ItemsControl IsTabStop="False" ItemsSource="{Binding Products}">
                                <prism:DataTemplateSelector Content="{Binding}" IsTabStop="False">
                                        <DataTemplate x:Key="ProductViewModel">
                                            <Views:ProductView DataContext="{Binding}"/>


Sep 1, 2011 at 5:57 PM

Let me reply myself: You need to use ItemsPanelTemplate as in the below example

<ItemsControl IsTabStop="False" ItemsSource="{Binding Products}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate>