private FrameworkElement CreateToggleButton(object parameter, ToolbarElement element, bool isContextual, Func <object> getContext) { var command = element.Element as ICommand; if (command == null) { return(null); } BitmapImage iconSource = null; if (element.Icon != null || element.ElementType != RibbonElementType.SmallToggleButton) { var icon = element.Icon != null ? new Icon(element.Icon) : Icon.Empty; iconSource = icon.GetSource(); } var button = new ToggleButton() { Header = string.IsNullOrEmpty(element.Text) ? command.Text : element.Text, IsEnabled = command.CanExecute(parameter), Icon = iconSource, LargeIcon = iconSource, SizeDefinition = element.ElementType == RibbonElementType.SmallToggleButton ? "Middle" : "Large" }; if (!string.IsNullOrEmpty(command.ToolTip)) { button.ToolTip = command.ToolTip; } if (!string.IsNullOrEmpty(command.InputGestureText)) { button.KeyTip = command.InputGestureText; } button.Click += delegate { var context = getContext(); if (context == null) { return; } if (command.CanExecute(context)) { command.Execute(context); } }; if (!isContextual) { _toolbarButtons[button] = command; } return(button); }
private UIElement CreateCheckbox(object parameter, ToolbarElement element, bool isContextual, Func <object> getContext) { var command = element.Element as ICommand; if (command == null) { return(null); } var checkBox = new Fluent.CheckBox { Header = !string.IsNullOrEmpty(element.Text) ? element.Text : command.Text, IsEnabled = command.CanExecute(parameter), IsChecked = command.IsChecked }; if (!string.IsNullOrEmpty(command.ToolTip)) { checkBox.ToolTip = command.ToolTip; } if (!string.IsNullOrEmpty(command.InputGestureText)) { checkBox.KeyTip = command.InputGestureText; } checkBox.Click += delegate { var context = getContext(); if (context == null) { return; } if (command.CanExecute(context)) { command.Execute(context); } }; if (!isContextual) { _toolbarButtons[checkBox] = command; } return(checkBox); }
private UIElement CreateGallery(object parameter, ToolbarElement element) { var gallery = element.Element as IToolbarGalleryFactory; if (gallery == null) { return(null); } var result = new InRibbonGallery { Header = element.Text }; gallery.Create(result, parameter); return(result); }
private DropDownButton CreateDropDown(object parameter, ToolbarElement element, bool isContextual, Func <object> getContext) { var command = element.Element as ICommand; if (command == null) { return(null); } var icon = Icon.Empty; if (element.Icon != null) { icon = new Icon(element.Icon); } var iconSource = icon.GetSource(); var button = new DropDownButton { Header = !string.IsNullOrEmpty(element.Text) ? element.Text : command.Text, IsEnabled = command.CanExecute(parameter), Icon = iconSource, LargeIcon = iconSource, }; button.DropDownOpened += delegate { button.Items.Clear(); var submenuCommand = command; if (submenuCommand == null) { return; } var context = getContext(); if (context == null) { return; } var commands = submenuCommand.GetSubmenuCommands(context).ToList(); string group = null; foreach (var c in commands.OrderBy(c => c.SortingValue).ThenBy(c => c.Text)) { var cmd = c; if (cmd.Group != group) { if (group != null) { button.Items.Add(new Separator()); } group = cmd.Group; } var menuItem = new Fluent.MenuItem { Header = cmd.Text, IsChecked = cmd.IsChecked }; if (!string.IsNullOrEmpty(command.ToolTip)) { menuItem.ToolTip = command.ToolTip; } if (!string.IsNullOrEmpty(command.InputGestureText)) { menuItem.KeyTip = command.InputGestureText; } if (cmd.Icon != null && cmd.Icon != Icon.Empty) { menuItem.Icon = cmd.Icon.GetSource(); } menuItem.Click += delegate { if (cmd.CanExecute(context)) { cmd.Execute(context); } }; button.Items.Add(menuItem); } }; if (!string.IsNullOrEmpty(command.ToolTip)) { button.ToolTip = command.ToolTip; } if (!string.IsNullOrEmpty(command.InputGestureText)) { button.KeyTip = command.InputGestureText; } if (!isContextual) { _toolbarButtons[button] = command; } return(button); }