private void TryRemoveSecondarySeparator() { if (SecondaryCommands.Any(x => x is AppBarSeparator) && ( SecondaryCommands.Count == 0 || !SecondaryCommands.Any(x => x is NavAppBarButton) || !SecondaryCommands.Any(x => x is ISortableAppBarButton) )) { int separatorIndex = SecondaryCommands.IndexOf(SecondaryCommands.First(x => x is AppBarSeparator)); SecondaryCommands.RemoveAt(separatorIndex); } }
private void InsertToSecondaryBar(NavAppBarButton buttonToMove) { buttonToMove.IsSecondaryCommand = true; if (SecondaryCommands.Any(x => x is MovableAppBarButton) && !SecondaryCommands.Any(x => x is AppBarSeparator)) { SecondaryCommands.Insert(0, new AppBarSeparator()); } int separatorIndex = -1; if (SecondaryCommands.Any(x => x is AppBarSeparator)) { separatorIndex = SecondaryCommands.IndexOf(SecondaryCommands.First(x => x is AppBarSeparator)); } int endIndex = separatorIndex != -1 ? separatorIndex - 1 : SecondaryCommands.Count - 1; if (endIndex == -1) //nothing in the SecondaryCommands list yet { SecondaryCommands.Add(buttonToMove); } else //we've got at least one other SecondaryCommand, maybe more { for (int i = 0; i <= endIndex; i++) { int currCommandPosition = ((ISortableAppBarButton)SecondaryCommands[i]).Position; if (buttonToMove.Position < currCommandPosition) { SecondaryCommands.Insert(i, buttonToMove); return; } } //if we get through the entire list and we don't find anything of a lesser priority, the new button belongs at the end SecondaryCommands.Insert(endIndex, buttonToMove); } }
private void InsertToSecondaryBar(ICommandBarElement buttonToMove) { ((ISortableAppBarButton)buttonToMove).IsSecondaryCommand = true; if (SecondaryCommands.Any(x => x is NavAppBarButton) && !SecondaryCommands.Any(x => x is AppBarSeparator)) { SecondaryCommands.Add(new AppBarSeparator()); } int separatorIndex = -1; if (SecondaryCommands.Any(x => x is AppBarSeparator)) { separatorIndex = SecondaryCommands.IndexOf(SecondaryCommands.First(x => x is AppBarSeparator)); } int startIndex = separatorIndex != -1 ? separatorIndex + 1 : 0; if (startIndex == 0) { SecondaryCommands.Add(buttonToMove); } else { for (int i = startIndex; i < SecondaryCommands.Count; i++) { int currCommandPosition = ((ISortableAppBarButton)SecondaryCommands[i]).Position; if (((ISortableAppBarButton)buttonToMove).Position < currCommandPosition) { SecondaryCommands.Insert(i, buttonToMove); return; } } //if we get through the entire list and we don't find anything of a lesser priority, the new button belongs at the end SecondaryCommands.Add(buttonToMove); } }