private void UpdateCommandsVisibilityTracking(IEnumerable <ICommandBarElement> sender) { List <ICommandBarElement> toRemove = new List <ICommandBarElement>(); foreach (KeyValuePair <ICommandBarElement, long> element in _visibilityTrackedElements) { var visibilityTrackable = element.Key as FrameworkElement; if (visibilityTrackable != null && !(PrimaryCommands.Contains(element.Key) || SecondaryCommands.Contains(element.Key))) { visibilityTrackable.UnregisterPropertyChangedCallback(VisibilityProperty, element.Value); } } foreach (var stale in toRemove) { _visibilityTrackedElements.Remove(stale); } foreach (ICommandBarElement element in sender) { if (element is NavAppBarButton) { continue; } var visibilityTrackable = element as FrameworkElement; if (visibilityTrackable != null && !_visibilityTrackedElements.ContainsKey(element)) { long callbackToken = visibilityTrackable.RegisterPropertyChangedCallback(VisibilityProperty, OnCommandBarElementVisibilityChanged); _visibilityTrackedElements.Add(element, callbackToken); } } }
private void HomeAppBarButtonOnClick(object sender, RoutedEventArgs routedEventArgs) { if (HomeButtonClicked != null && (PrimaryCommands.Any() || _isOpen)) { HomeButtonClicked(sender as Button, new EventArgs()); Hide(); } }
public void Hide() { _isOpen = false; if (_homeAppBarButton != null) { _homeAppBarButton.Opacity = PrimaryCommands.Any() ? 1 : 0; } }
private void ReleaseToggleButtons(AppBarToggleButton skip) { var items = PrimaryCommands.Where(r => r != skip && r.GetType() == typeof(AppBarToggleButton)).Cast <AppBarToggleButton>(); foreach (var item in items) { item.IsChecked = false; } }
public void Hide() { if (_fadeOutProperty != null) { _mainRegionRowDefinition.Height = PrimaryCommands.Any() ? new GridLength(60, GridUnitType.Pixel) : new GridLength(20, GridUnitType.Pixel); _fadeOutProperty.Begin(); _isOpen = false; _tapRowDefinition.Height = new GridLength(0, GridUnitType.Pixel); } if (_homeAppBarButton != null) { _homeAppBarButton.Opacity = PrimaryCommands.Any() ? 1 : 0; } }
protected override Size ArrangeOverride(Size finalSize) { var ret = base.ArrangeOverride(finalSize); if (!haveDynamicOverflow && primary.Count != 0) { uint limit = (uint)Math.Floor(ret.Width / 68) - 1; int currentCount = PrimaryCommands.CountVisible(); if (currentCount != limit && !(currentCount == primary.Count && limit > currentCount)) { reflowing = true; #if WINDOWS_APP secondaryFlyout = null; #endif needseparator = false; PrimaryCommands.Clear(); SecondaryCommands.Clear(); int i = 0; foreach (var item in primary) { if (i < limit) { PrimaryCommands.Add(item); } else { SecondaryCommands.Add(item); } i++; } needseparator = i > limit; foreach (var item in secondary) { SecondaryCommands.Add(item); } reflowing = false; } } return(ret); }
private void OnDefaultLabelPositionChanged(DependencyObject sender, DependencyProperty property) { bool areToolTipsVisible = DefaultLabelPosition == CommandBarDefaultLabelPosition.Collapsed; foreach (DependencyObject command in PrimaryCommands.Cast <DependencyObject>()) { string label = GetLabel(command); if (areToolTipsVisible) { ToolTipService.SetToolTip(command, label); } else { ToolTipService.SetToolTip(command, null); } } }
public void CreateCommandButton(ShellCommand command) { IconElement getIcon() { IconElement icon = null; if (command.Icon is SymbolIcon symbolicon) { icon = new SymbolIcon { Symbol = symbolicon.Symbol } } ; else if (command.Icon is FontIcon fonticon) { icon = new FontIcon { FontFamily = fonticon.FontFamily, Glyph = fonticon.Glyph } } ; command.Icons.Add(icon); return(icon); } if (command is ToggleShellCommand togglecommand) { var button = new AppBarToggleButton() { DataContext = command, Label = command.Label, Icon = getIcon() }; button.Click += delegate { togglecommand.Toggled = button.IsChecked.Value; command.Action.Invoke(); }; PrimaryCommands.Add(button); command.IconReplacementRequested += delegate { command.Icons.Remove(button.Icon); button.Icon = getIcon(); }; command.LabelReplacementRequested += delegate { button.Label = command.Label; }; } else { var button = new AppBarButton() { DataContext = command, Label = command.Label, Icon = getIcon() }; button.Click += delegate { command.Action?.Invoke(); }; PrimaryCommands.Add(button); command.IconReplacementRequested += delegate { command.Icons.Remove(button.Icon); button.Icon = getIcon(); }; command.LabelReplacementRequested += delegate { button.Label = command.Label; }; } HasItems = true; TryShowItems(); }
private void SetMode(MultiModeEditorCommandBarMode newMode) { switch (_currentMode) { case MultiModeEditorCommandBarMode.Normal: PrimaryCommands.Remove(_newButton); PrimaryCommands.Remove(_selectButton); PrimaryCommands.Remove(_reorderButton); PrimaryCommands.Remove(_playButton); break; case MultiModeEditorCommandBarMode.Reorder: PrimaryCommands.Remove(_finishedReorderingButton); break; case MultiModeEditorCommandBarMode.Select: PrimaryCommands.Remove(_deleteButton); PrimaryCommands.Remove(_copyButton); PrimaryCommands.Remove(_cancelSelectionButton); break; default: throw new ArgumentOutOfRangeException(); } switch (newMode) { case MultiModeEditorCommandBarMode.Normal: PrimaryCommands.Add(_newButton); PrimaryCommands.Add(_selectButton); if (TargetType == AppBarTargetType.Object) { PrimaryCommands.Add(_reorderButton); } PrimaryCommands.Add(_playButton); _playButton.IsEnabled = true; break; case MultiModeEditorCommandBarMode.Reorder: PrimaryCommands.Add(_finishedReorderingButton); _playButton.IsEnabled = false; break; case MultiModeEditorCommandBarMode.Select: PrimaryCommands.Add(_deleteButton); PrimaryCommands.Add(_copyButton); PrimaryCommands.Add(_cancelSelectionButton); _playButton.IsEnabled = false; break; default: throw new ArgumentOutOfRangeException("newMode"); } _currentMode = newMode; if (ModeChanged != null) { Mode = newMode; ModeChanged.Invoke(newMode); } }
public RichEditBoxSelectionFlyout() { Opened += RichEditBoxSelectionFlyout_Opened; Placement = Windows.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.TopEdgeAlignedLeft; ResourceLoader loader = ResourceLoader.GetForCurrentView(); CutButton = new AppBarButton() { Label = loader.GetString("CutButton/Text") }; CutButton.Click += CutButton_Click; PrimaryCommands.Add(CutButton); CopyButton = new AppBarButton() { Label = loader.GetString("CopyButton/Text") }; CopyButton.Click += CopyButton_Click; PrimaryCommands.Add(CopyButton); PasteButton = new AppBarButton() { Label = loader.GetString("PasteButton/Text") }; PasteButton.Click += PasteButton_Click; PrimaryCommands.Add(PasteButton); SelectAllButton = new AppBarButton() { Label = loader.GetString("SelectAllButton/Text") }; SelectAllButton.Click += SelectAllButton_Click; SecondaryCommands.Add(SelectAllButton); HighlightSeparator = new AppBarSeparator(); SecondaryCommands.Add(HighlightSeparator); HighlightButton = new AppBarButton() { Label = loader.GetString("HighlightButton/Text") }; HighlightButton.Click += HighlightButton_Click; SecondaryCommands.Add(HighlightButton); RemoveHighlightButton = new AppBarButton() { Label = loader.GetString("RemoveHighlightButton/Text") }; RemoveHighlightButton.Click += RemoveHighlightButton_Click; SecondaryCommands.Add(RemoveHighlightButton); CaseSeparator = new AppBarSeparator(); SecondaryCommands.Add(CaseSeparator); UppercaseButton = new AppBarButton() { Label = loader.GetString("UppercaseButton/Text") }; UppercaseButton.Click += UppercaseButton_Click; SecondaryCommands.Add(UppercaseButton); LowercaseButton = new AppBarButton() { Label = loader.GetString("LowercaseButton/Text") }; LowercaseButton.Click += LowercaseButton_Click; SecondaryCommands.Add(LowercaseButton); SearchSeparator = new AppBarSeparator(); SecondaryCommands.Add(SearchSeparator); SearchButton = new AppBarButton() { Label = "[search]" }; SearchButton.Click += SearchButton_Click; SecondaryCommands.Add(SearchButton); CutButton.Icon = new FontIcon { Glyph = "\uE8C6" }; CopyButton.Icon = new FontIcon { Glyph = "\uE8C8" }; PasteButton.Icon = new FontIcon { Glyph = "\uE77F" }; if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Input.KeyboardAccelerator")) { KeyboardAccelerator CtrlX = new KeyboardAccelerator(); CtrlX.Key = VirtualKey.X; CtrlX.Modifiers = VirtualKeyModifiers.Control; CtrlX.IsEnabled = false; CutButton.AccessKey = "X"; CutButton.KeyboardAccelerators.Add(CtrlX); KeyboardAccelerator CtrlC = new KeyboardAccelerator(); CtrlC.Key = VirtualKey.C; CtrlC.Modifiers = VirtualKeyModifiers.Control; CtrlC.IsEnabled = false; CopyButton.AccessKey = "C"; CopyButton.KeyboardAccelerators.Add(CtrlC); KeyboardAccelerator CtrlV = new KeyboardAccelerator(); CtrlV.Key = VirtualKey.V; CtrlV.Modifiers = VirtualKeyModifiers.Control; CtrlV.IsEnabled = false; PasteButton.AccessKey = "V"; PasteButton.KeyboardAccelerators.Add(CtrlV); KeyboardAccelerator CtrlA = new KeyboardAccelerator(); CtrlA.Key = VirtualKey.A; CtrlA.Modifiers = VirtualKeyModifiers.Control; CtrlA.IsEnabled = false; SelectAllButton.AccessKey = "A"; SelectAllButton.KeyboardAccelerators.Add(CtrlA); } }
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); } } }