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); } } }
public BitmapIcon() { Foreground = SolidColorBrushHelper.Black; _image = new Image { Stretch = Media.Stretch.Uniform, #if !NET461 MonochromeColor = (Foreground as SolidColorBrush)?.Color #endif }; _image.SetBinding( dependencyProperty: Image.SourceProperty, binding: new Binding { Source = this, Path = nameof(UriSource) } ); _grid = new Grid(); _grid.Children.Add(_image); AddIconElementView(_grid); }