private void FocusNextItem(bool down)
{
int count = Items.Count;
int startingIndex = down ? -1 : count;
MenuItem focusedMenuItem = FocusManager.GetFocusedElement() as MenuItem;
if (null != focusedMenuItem && (this == focusedMenuItem.ParentMenuBase))
{
startingIndex = ItemContainerGenerator.IndexFromContainer(focusedMenuItem);
}
int index = startingIndex;
do
{
index = (index + count + (down ? 1 : -1)) % count;
MenuItem container = ItemContainerGenerator.ContainerFromIndex(index) as MenuItem;
if (null != container)
{
if (container.IsEnabled && container.Focus())
{
break;
}
}
}
while (index != startingIndex);
}