Do you know any controls inherited from the ItemsControl that have horizontal orientation of items?
5 Answers
Simply change the panel used to host the items:
<ItemsControl ...>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>

- 175,602
- 35
- 392
- 393
-
Don't you need to add IsItemsHost="True" to the StackPanel ? – Thomas Levesque Jun 27 '09 at 09:56
-
5I believe that's only necessary if you're re-templating the entire control. See http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemspanel.aspx – Kent Boogaart Jun 27 '09 at 10:10
-
3Answer also holds for Silverlight – Scott Apr 23 '10 at 06:53
-
how to do this in a resource file? – Florian Oct 23 '13 at 12:16
-
To do this in a resource file, you need to set the x:Key key – Tore Aurstad Mar 27 '19 at 11:50
-
2I wish you could just do something like `StackPanel.Orientation="Horizontal"` in the main tag! – Jonathan Tuzman Jul 23 '20 at 16:32
-
1Just to make it absolutely clear for everyone (even XAML/WPF/UWP newcomers), you should ADD the `ItemsControl.ItemsPanel` to your `ItemsControl`, you should NOT REPLACE your `ItemsControl.ItemTemplate` with the `ItemsControl.ItemsPanel` – Pedro Martins Timóteo da Costa Jan 03 '21 at 20:40
-
Answer also holds on Avalonia – Pedro Martins Timóteo da Costa Jan 03 '21 at 20:40
While the promoted answer is great, here's an alternative if you want the items to stretch.
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

- 3,626
- 1
- 30
- 38
-
If you're using UWP, you'll need UWP-UniformGrid from here: https://github.com/rickapps/UWP-UniformGrid-Control. I just implemented it plus NielW's solution above. Really easy and solves the problem. – Gail Foad Dec 07 '17 at 16:47
This is an example of how to do horizontal scrolling within an ItemsControl.
Firstly the main window viewmodel class used to get/set the list of items we wish to display.
MainWindowViewModel.cs
using System.Collections.Generic;
namespace ItemsControl
{
public class Item
{
public Item(string title)
{
Title = title;
}
public string Title { get; set; }
}
public class MainWindowViewModel
{
public MainWindowViewModel()
{
Titles = new List<Item>()
{
new Item("Slide 1"),
new Item("Slide 2"),
new Item("Slide 3"),
new Item("Slide 4"),
new Item("Slide 5"),
new Item("Slide 6"),
new Item("Slide 7"),
new Item("Slide 8"),
};
}
public List<Item> Titles { get; set; }
}
}
The main window xaml for the view:
MainWindow.xaml
<Window x:Class="ItemsControl.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ItemsControl"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="400">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Grid Margin="5">
<ScrollViewer
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Auto">
<ItemsControl
x:Name="SearchResultList"
ItemsSource="{Binding Titles}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border
Margin="5"
BorderThickness="1"
BorderBrush="Aqua">
<TextBlock
Text="{Binding Title}"
HorizontalAlignment="Center"
VerticalAlignment="Top"
FontSize="12"
TextWrapping="Wrap"
TextAlignment="Center"
FontWeight="DemiBold"
Width="150"
Height="150" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</Window>
Depending on how high/wide your client area is, this will result in this kind of layout, overflow items scrolled horizontally:
More details can be found at this blog link, including an example on how to do the scrolling vertically:

- 3,933
- 7
- 42
- 44
The top answer is good, but I couldn't get it to work with UserControls. If you need UserControls, this should help.
ItemsControl with Horizontal Usercontrols
My Version:
<Window.Resources>
<DataTemplate x:Key="ItemTemplate2">
<StackPanel>
<uc:MyUserControl MinWidth="20" BorderBrush="Black" BorderThickness="0.1" />
</StackPanel>
</DataTemplate>
<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
<StackPanel Orientation="Horizontal" Margin="0,0,0,0"/>
</ItemsPanelTemplate>
</Window.Resources>
<StackPanel>
<ItemsControl x:Name="list_MyControls"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,8,0,0"
ItemTemplate="{StaticResource ItemTemplate2}"
ItemsPanel="{StaticResource ItemsPanelTemplate1}" />
</StackPanel>
To bind to data, you will need to add an ItemsSource
to the ItemsControl
in the XAML or code behind. Also note that uc:
would be the xmlns:uc="NamespaceOfMyControl"
declared at the top of the file.

- 7,287
- 7
- 50
- 85

- 16,260
- 18
- 100
- 123
-
I'm not used to using WPF, so maybe what i will say is very basic stuff. I found out that inside an UserControl you should use "UserControl.Resources" instead of "Window.Resources". Anyway, thanks for the great answer, solved my problem. – Paulo André Haacke Dec 07 '17 at 12:23
For a long list with hundreds or even thousands of items, you should better use VirtualizingStackPanel to avoid performance issues.

- 49
- 6
-
this is an 11 year old question, I would hope it's been resolved already ;) – AntLaC Jul 31 '20 at 17:42
-
1Just added this comment to make the solution more complete :) Because you know, this WPF, it's so unfriendly framework, sometimes unpredictable, and with latest VS 2019 crashes so annoying XD – Evgenii Aug 01 '20 at 19:49