Cannot center the wrap panel


I don't seem to be able to center the contents of the wrap panel on the screen. I notice that the following appears in the output window:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ListBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

It alternates between the above and a similar error for the HorizontalContentAlignment. Attached is the source code for my control. This works correctly when I use a standard WrapPanel

file attachments