1) If you don't want headers use a ListBox instead with a WrapPanel.
2) Why are you adding UIElement to a items control? Most likely you want to use data binding. Specially if you want to sort them. How do you sort UIElements?
Below are some code that uses data binding. Hope you can use it.
XAML:
<Window x:Class="ListViewTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Row="0" Content="Sort" Click="OnSort" />
<ListBox Grid.Row="1" ItemsSource="{Binding Path=MyCollectionView}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="2" Margin="5">
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Code behind:
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace ListViewTest
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
List<object> myCollection = new List<object>();
for (int i = 100; i <= 999; i++)
{
myCollection.Add(i);
}
MyCollectionView = new ListCollectionView(myCollection);
MyCollectionView.CustomSort = _mySort;
DataContext = this;
}
public ListCollectionView MyCollectionView { get; private set; }
private void OnSort(object sender, RoutedEventArgs e)
{
_mySort.Ascending = !_mySort.Ascending;
MyCollectionView.Refresh();
}
private MySort _mySort = new MySort();
private class MySort : IComparer
{
public bool Ascending { get; set; }
#region IComparer Members
public int Compare(object x, object y)
{
return x.ToString().CompareTo(y.ToString()) * (Ascending ? -1 : 1);
}
#endregion
}
}
}