Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        private void VectorChanged(Windows.Foundation.Collections.IObservableVector <ICommandBarElement> sender, Windows.Foundation.Collections.IVectorChangedEventArgs args)
        {
            if (args.CollectionChange == Windows.Foundation.Collections.CollectionChange.Reset)
            {
#if WINDOWS_APP
                secondaryFlyout = null;
#endif
                needseparator = false;
                if (!reflowing)
                {
                    primary.Clear();
                    secondary.Clear();
                }
            }
            else if (args.CollectionChange == Windows.Foundation.Collections.CollectionChange.ItemInserted)
            {
                var itembase = sender[(int)args.Index];
                itembase.IsCompact = true;

#if WINDOWS_APP
                if (sender == SecondaryCommands)
                {
                    if (secondaryFlyout == null)
                    {
                        var ellipsis = new AppBarEllipsis
                        {
                            Flyout = secondaryFlyout = new MenuFlyout()
                        };

                        PrimaryCommands.Add(ellipsis);
                        secondaryFlyout.Opening += SecondaryFlyout_Opening;
                        secondaryFlyout.Closed  += SecondaryFlyout_Closed;
                    }

                    if (needseparator)
                    {
                        needseparator = false;
                        secondaryFlyout.Items.Add(new MenuFlyoutSeparator());
                    }

                    if (itembase is AppBarSeparator sep)
                    {
                        secondaryFlyout.Items.Add(new MenuFlyoutSeparator());
                    }
                    else if (itembase is AppBarButton button)
                    {
                        if (!reflowing && !primary.Contains(button))
                        {
                            secondary.Add(button);
                        }

                        var menuitem = new MenuFlyoutItemEx
                        {
                            Text        = button.Label,
                            Command     = button.Command,
                            DataContext = button.DataContext,
                        };
                        if (button.Icon is BitmapIcon bmp)
                        {
                            menuitem.Icon = new BitmapIcon {
                                UriSource = bmp.UriSource
                            }
                        }
                        ;
                        else if (button.Icon is SymbolIcon sym)
                        {
                            menuitem.Icon = new SymbolIcon(sym.Symbol);
                        }

                        if (menuitem.DataContext is Ao3TrackReader.Controls.ToolbarItem)
                        {
                            // Create the binding description.
                            Binding b = new Binding()
                            {
                                Mode      = BindingMode.OneWay,
                                Path      = new PropertyPath("Foreground"),
                                Converter = new ColorConverter()
                            };
                            menuitem.SetBinding(MenuFlyoutItemEx.ForegroundProperty, b);
                        }

                        secondaryFlyout.Items.Add(menuitem);
                    }

                    if (itembase is FrameworkElement elem)
                    {
                        elem.Visibility = Visibility.Collapsed;
                    }

                    return;
                }
#endif

                if (itembase is FrameworkElement e)
                {
                    e.Visibility = Visibility.Visible;
                }

                var item = itembase as AppBarButton;
                if (item == null)
                {
                    return;
                }
                if (AppBarButtonTemplate != null)
                {
                    item.Template = AppBarButtonTemplate;
                }

                var xitem = item.DataContext as Xamarin.Forms.ToolbarItem;
                if (xitem == null)
                {
                    return;
                }

                if (sender == PrimaryCommands)
                {
                    if (!reflowing)
                    {
                        primary.Add(item);

                        if (!haveDynamicOverflow && ActualWidth > 0)
                        {
                            uint limit = (uint)Math.Floor(ActualWidth / 68) - 1;
                            if (args.Index >= limit)
                            {
                                item.Visibility = Visibility.Collapsed;
                                needseparator   = false;
                                var newitem = new AppBarButton
                                {
                                    Label       = item.Label,
                                    Command     = item.Command,
                                    DataContext = item.DataContext
                                };
                                if (item.Icon is BitmapIcon bmp)
                                {
                                    newitem.Icon = new BitmapIcon {
                                        UriSource = bmp.UriSource
                                    }
                                }
                                ;
                                else if (item.Icon is SymbolIcon sym)
                                {
                                    newitem.Icon = new SymbolIcon(sym.Symbol);
                                }
                                SecondaryCommands.Add(newitem);

                                needseparator = true;

                                return;
                            }
                        }
                    }
                }
                else if (sender == SecondaryCommands)
                {
                    if (needseparator)
                    {
                        needseparator = false;
#if !WINDOWS_PHONE_APP
                        SecondaryCommands.Insert((int)args.Index, new AppBarSeparator());
#else
                        SecondaryCommands.Insert((int)args.Index, new AppBarButton {
                            Label     = "\x23AF\x23AF\x23AF\x23AF",
                            IsEnabled = false,
                        });
#endif
                    }
                    if (!reflowing)
                    {
                        secondary.Add(item);
                    }

                    var ti = GetTemplateChild("SecondaryItemsControl");
                }

                item.ClearValue(AppBarButton.IconProperty);
                if (!string.IsNullOrWhiteSpace(xitem.Icon?.File))
                {
#if !WINDOWS_PHONE_APP
                    var uri = new Uri("ms-appx:///" + xitem.Icon.File);
#else
                    var uri = new Uri("ms-appx:///Appbar/" + xitem.Icon.File);
#endif
                    item.Icon = new BitmapIcon()
                    {
                        UriSource = uri
                    };
                }

                if (item.DataContext is Ao3TrackReader.Controls.ToolbarItem)
                {
                    // Create the binding description.
                    Binding b = new Binding()
                    {
                        Mode      = BindingMode.OneWay,
                        Path      = new PropertyPath("Foreground"),
                        Converter = new ColorConverter()
                    };
                    item.SetBinding(AppBarButton.ForegroundProperty, b);
                }
            }
        }