Exemple #1
0
        internal async Task UpdateToolbarItems()
        {
            var toolbarProvider = GetToolbarProvider();

            if (toolbarProvider == null)
            {
                return;
            }

            CommandBar commandBar = await toolbarProvider.GetCommandBarAsync();

            if (commandBar == null)
            {
                return;
            }

            commandBar.PrimaryCommands.Clear();
            commandBar.SecondaryCommands.Clear();

            var toolBarForegroundBinder = GetToolbarProvider() as IToolBarForegroundBinder;

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems)
            {
                toolBarForegroundBinder?.BindForegroundColor(commandBar);

                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");

                if (commandBar.IsDynamicOverflowEnabled && item.Order == ToolbarItemOrder.Secondary)
                {
                    button.SetBinding(AppBarButton.IconProperty, "IconImageSource", _imageSourceIconElementConverter);
                }
                else
                {
                    var img = new WImage();
                    img.SetBinding(WImage.SourceProperty, "Value");
                    img.SetBinding(WImage.DataContextProperty, "IconImageSource", _imageConverter);
                    button.Content = img;
                }

                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;
                button.SetValue(NativeAutomationProperties.AutomationIdProperty, item.AutomationId);
                button.SetAutomationPropertiesName(item);
                button.SetAutomationPropertiesAccessibilityView(item);
                button.SetAutomationPropertiesHelpText(item);
                button.SetAutomationPropertiesLabeledBy(item);

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    toolBarForegroundBinder?.BindForegroundColor(button);
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }
        }
Exemple #2
0
        internal void UpdateMenu()
        {
            if (Handler.PlatformView is not MauiToolbar wh)
            {
                return;
            }

            var commandBar = wh.CommandBar;

            if (commandBar == null)
            {
                return;
            }

            commandBar.PrimaryCommands.Clear();
            commandBar.SecondaryCommands.Clear();

            List <ToolbarItem> toolbarItems = new List <ToolbarItem>(ToolbarItems ?? Array.Empty <ToolbarItem>());

            foreach (ToolbarItem item in toolbarItems)
            {
                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");

                if (commandBar.IsDynamicOverflowEnabled && item.Order == ToolbarItemOrder.Secondary)
                {
                    button.SetBinding(AppBarButton.IconProperty, "IconImageSource", _imageSourceIconElementConverter);
                }
                else if (!item.IconImageSource.IsNullOrEmpty())
                {
                    var img = new WImage();
                    img.SetBinding(WImage.SourceProperty, "Value");
                    img.SetBinding(WImage.DataContextProperty, "IconImageSource", _imageConverter);
                    button.Content = img;
                }

                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;
                button.SetValue(NativeAutomationProperties.AutomationIdProperty, item.AutomationId);
                button.SetAutomationPropertiesName(item);
                button.SetAutomationPropertiesAccessibilityView(item);
                button.SetAutomationPropertiesHelpText(item);
                button.UpdateTextColor(BarTextColor);

                button.SetAutomationPropertiesLabeledBy(item, null);

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }
        }
Exemple #3
0
        internal async Task UpdateToolbarItems()
        {
            var toolbarProvider = GetToolbarProvider();

            if (toolbarProvider == null)
            {
                return;
            }

            CommandBar commandBar = await toolbarProvider.GetCommandBarAsync();

            if (commandBar == null)
            {
                return;
            }

            commandBar.PrimaryCommands.Clear();
            commandBar.SecondaryCommands.Clear();

            var toolBarForegroundBinder = GetToolbarProvider() as IToolBarForegroundBinder;

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority))
            {
                toolBarForegroundBinder?.BindForegroundColor(commandBar);

                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");
                button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter);
                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;
                button.SetValue(NativeAutomationProperties.AutomationIdProperty, item.AutomationId);
                button.SetAutomationPropertiesName(item);
                button.SetAutomationPropertiesAccessibilityView(item);
                button.SetAutomationPropertiesHelpText(item);
                button.SetAutomationPropertiesLabeledBy(item);

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    toolBarForegroundBinder?.BindForegroundColor(button);
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }
        }