/// <summary>
/// To get the active container, like pannel,canvas or grid from the items panel
/// </summary>
/// <param name="visual">ItemsControl</param>
/// <returns></returns>
public static object FindItemsPanel(Visual visual)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
    {
        Visual child = VisualTreeHelper.GetChild(visual, i) as Visual;
        if (child != null)
        {
            if (child is object && VisualTreeHelper.GetParent(child) is ItemsPresenter)
            {
                object temp = child;
                return (object)temp;
            }
            object panel = FindItemsPanel(child);
            if (panel != null)
            {
                object temp = panel;
                return (object)temp; // return the panel up the call stack
            }
        }
    }
    return default(object);
}


<ItemsControl>
	<ItemsControl.ItemsPanel>
		<ItemsPanelTemplate>
    		<StackPanel />
		</ItemsPanelTemplate>
	</ItemsControl.ItemsPanel>
</ItemsControl