public void RefreshComponent() { foreach (FrameworkElement item in Items) { if (!_listElement.Contains(item)) { item.Loaded += Item_Loaded; _listElement.Add(item); } } if (Items.Count != _listElement.Count) { for (int i = 0; i < _listElement.Count; i++) { if (!Items.Contains(_listElement[i])) { _listElement[i].Loaded -= Item_Loaded; AdvancedMenuItems.Remove(_listElement[i]); BasedMenuItems.Remove(_listElement[i]); _listElement.RemoveAt(i); DefineItemsInMenu(); } } } }
private void DefineItemsInMenu() { double intermediateHeight = 0; int nbVisibleElement = 0; foreach (FrameworkElement element in _listElement) { intermediateHeight += element.ActualHeight + BaseButtonsMargin.Bottom + BaseButtonsMargin.Top; if (ActualHeight >= intermediateHeight) { nbVisibleElement++; } else { break; } } if (_listElement.Count > nbVisibleElement) { MenuVisibility = Visibility.Visible; nbVisibleElement--; } else { MenuVisibility = Visibility.Collapsed; } for (int i = 0; i < _listElement.Count; i++) { if (i < nbVisibleElement) { if (AdvancedMenuItems.Contains(_listElement[i])) { AdvancedMenuItems.Remove(_listElement[i]); } if (!BasedMenuItems.Contains(_listElement[i])) { _listElement[i].Margin = BaseButtonsMargin; FrameworkElement element = _listElement[i]; BasedMenuItems.Add(element); } } else { if (BasedMenuItems.Contains(_listElement[i])) { BasedMenuItems.Remove(_listElement[i]); } if (!AdvancedMenuItems.Contains(_listElement[i])) { _listElement[i].Margin = SecondaryButtonsMargin; AdvancedMenuItems.Add(_listElement[i]); } } } }