It seems that when loading ContextMenu
ScrollContentPresenter
menu is not set to the correct value, trimming ItemPresenter
MenuItem
(Below is an abridged version of the visual tree showing the problem).
PopupRoot, Acutal Width: 219,027, Desired Width: 219,027 Decorator, Acutal Width: 219,027, Desired Width: 219,027 NonLogicalAdornerDecorator, Acutal Width: 219,027, Desired Width: 219,027 ContextMenuProxy, Acutal Width: 219,027, Desired Width: 219,027 SystemDropShadowChrome, Acutal Width: 214,027, Desired Width: 219,027 Border, Acutal Width: 214,027, Desired Width: 214,027 Grid, Acutal Width: 212,027, Desired Width: 212,027 Rectangle, Acutal Width: 28,000, Desired Width: 32,000 Rectangle, Acutal Width: 1,000, Desired Width: 31,000 Rectangle, Acutal Width: 1,000, Desired Width: 32,000 ScrollViewer, Acutal Width: 210,027, Desired Width: 212,027 Grid, Acutal Width: 210,027, Desired Width: 210,027 Border, Acutal Width: 210,027, Desired Width: 210,027 ScrollContentPresenter, Acutal Width: 210,027, Desired Width: 210,027 ItemsPresenter, Acutal Width: 241,047, Desired Width: 245,047
An invalid measure of the visual root of ContextMenu
( PopupRoot
) when loading the menu should result in a layout update to display the correct borders for the ItemsPresenter
.
Handler for the Download Event menu:
private void mainMenu_Loaded(object sender, RoutedEventArgs e) { if (sender != null) { ContextMenu menu = sender as ContextMenu; if (menu != null) {
GetVisualTreeRoot Method:
private DependencyObject GetVisualTreeRoot(DependencyObject control) { DependencyObject parent = VisualTreeHelper.GetParent(control); if (parent != null) { return GetVisualTreeRoot(parent); } else { return control; } }