I have created several MenuItems (not in XAML) so i added them the parent item :
( Parent_Menu as MenuItem ).Items.Add( Menu_Item );
Then i applied my styles by VisualTree list (in a loop) . But the styles won't apply on the new MenuItems . Here is my style applying code :
else if ( Visual is MenuItem )
{
MenuItem menuItem = Visual as MenuItem;
menuItem.Style = D_Interface.Style_Menu;
}
The parent menuitems got the styles but not the new sub menuitems . So I just checked with the debugger which items are linked to the parent items by the visual tree , And i cannot find the new sub items in the parent items . I guess they are not linked to the parent also in the logical tree .
I checked where the new subitems are in the global visual\logical tree , as i understood from the debugger that they are not linked to any parent not in the visual tree and not in the logical tree and not even to the Window itself .
My conclusion is that they are related to the parent MenuItem only by the "Items" list ... It's not the same like MenuItems are being children of a parent Menu control automatically .
Do anybody have idea how to make the dynamically created MenuItems to be children of the parent in the visual tree ?