I found this tutorial Using a Grid as the Panel for an ItemsControl but I couldn't get it to work.
I get this exception:
'Cannot explicitly modify Children collection of Panel used as ItemsPanel for ItemsControl. ItemsControl generates child elements for Panel.'
caused by grid.Children.Add(child)
in this loop
foreach (FrameworkElement child in phantom.Children.ToList())
{
phantom.Children.Remove(child);
grid.Children.Add(child);
// ensure the child maintains its original datacontext
child.DataContext = phantom.DataContext;
}
Is there any work around possible by inheriting from ItemsPanel
?