protected override Size MeasureOverride(Size availableSize) { Size desiredSize = new Size(); UIElementCollection children = InternalChildren; IItemContainerGenerator generator = ItemContainerGenerator; int itemsCount = 0; if (generator != null) { int StartItemIndex = navigationPane.GetFirstItemIndex(DisplayType); if (StartItemIndex > -1) { int maxItems = DisplayType == NavigationPaneItemDisplayType.Large ? navigationPane.LargeItems : int.MaxValue; GeneratorPosition startPos = new GeneratorPosition(-1, StartItemIndex + 1); using (generator.StartAt(startPos, GeneratorDirection.Forward, true)) { bool sizeExceeded = false; bool newlyRealized; UIElement child = null; // temp fix for {Disconnected Item} // needs more inspecting and documentation to fix it correctly !! // but this for now seems to work... strange items present ?? // remove them, NOW !!!!! //for (int j = children.Count - 1; j > -1; j--) //{ //UIElement item = children[j]; //object o = navigationPane.ItemContainerGenerator.ItemFromContainer(item); //if (o == DependencyProperty.UnsetValue) // RemoveInternalChild(item); //} while (!sizeExceeded && (itemsCount < maxItems) && (child = generator.GenerateNext(out newlyRealized) as UIElement) != null) { bool isExcluded = NavigationPane.GetIsItemExcluded(child); if (!isExcluded) { if (newlyRealized || !children.Contains(child)) { int absoluteIndex = StartItemIndex + itemsCount; int index = GetInsertIndex(absoluteIndex); if (absoluteIndex < 9 && navigationPane.ItemsKeyAuto) { NavigationPaneItem f = child as NavigationPaneItem; { Window w = Window.GetWindow(child); if (w != null) { KeyBinding binding = f.keyBinding; if (binding != null) { w.InputBindings.Remove(binding); } f.keyBinding = new KeyBinding(NavigationPane.SelectItemCommand, Key.D1 + absoluteIndex, navigationPane.ItemsKeyModifiers); f.keyBinding.CommandParameter = child; f.keyBinding.CommandTarget = navigationPane; w.InputBindings.Add(f.keyBinding); if (f != null) { f.Gesture = (f.keyBinding.Gesture as KeyGesture).GetDisplayStringForCulture(CultureInfo.CurrentCulture); } } } } SetActivePanel(child, this); SetAbosluteIndex(child, absoluteIndex); SetItemDisplayType(child, DisplayType); if (newlyRealized) { generator.PrepareItemContainer(child); } InsertInternalChild(index, child); } #region measurament algoritm Size childSize = new Size(); if (Orientation == Orientation.Vertical) { childSize = new Size(availableSize.Width, double.PositiveInfinity); } else { childSize = new Size(double.PositiveInfinity, availableSize.Height); } child.Measure(childSize); if (Orientation == Orientation.Vertical) { sizeExceeded = desiredSize.Height + child.DesiredSize.Height > availableSize.Height; if (!sizeExceeded) { desiredSize.Width = Math.Max(desiredSize.Width, child.DesiredSize.Width); desiredSize.Height += child.DesiredSize.Height; } } else { sizeExceeded = desiredSize.Width + child.DesiredSize.Width > availableSize.Width; if (!sizeExceeded) { desiredSize.Width += child.DesiredSize.Width; desiredSize.Height = Math.Max(desiredSize.Height, child.DesiredSize.Height); } } #endregion if (!sizeExceeded) { itemsCount++; } } else { RemoveInternalChild(child); } } } CleanUpItems(StartItemIndex, itemsCount); } } if (DisplayType == NavigationPaneItemDisplayType.Small) { navigationPane.SmallItems = itemsCount; } return(desiredSize); }