protected override void OnApplyTemplate() { base.OnApplyTemplate(); _moreButton = GetTemplateChild(MoreButton) as Button; _overflowPopup = GetTemplateChild(OverflowPopup) as Popup; _primaryItemsControl = GetTemplateChild(PrimaryItemsControl) as ItemsControl; _secondaryItemsControl = GetTemplateChild(SecondaryItemsControl) as ItemsControl; #if __ANDROID__ || __IOS__ Presenter = this.FindFirstChild <NativeCommandBarPresenter>(); #endif if (_moreButton != null) { _moreButton.Click += (s, e) => { IsOpen = !IsOpen; }; } if (_overflowPopup != null) { _overflowPopup.Closed += (s, e) => { IsOpen = false; }; } PrimaryCommands.VectorChanged += (s, e) => UpdateCommands(); SecondaryCommands.VectorChanged += (s, e) => UpdateCommands(); UpdateCommands(); this.RegisterPropertyChangedCallback(IsEnabledProperty, (s, e) => UpdateCommonState()); this.RegisterPropertyChangedCallback(ClosedDisplayModeProperty, (s, e) => UpdateDisplayModeState()); this.RegisterPropertyChangedCallback(IsOpenProperty, (s, e) => { // TODO: Consider the content of _secondaryItemsControl when IsDynamicOverflowEnabled is supported. var hasSecondaryItems = SecondaryCommands.Any(); if (hasSecondaryItems) { if (_overflowPopup != null) { _overflowPopup.IsOpen = true; } } UpdateDisplayModeState(); UpdateButtonsIsCompact(); }); UpdateCommonState(); UpdateDisplayModeState(); UpdateButtonsIsCompact(); }
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); } }