public CommandWithTextBlock(CommandLocation beginCommandLocation, CommandLocation endCommandLocation, string overallString = null) { BeginCommandLocation = beginCommandLocation; EndCommandLocation = endCommandLocation; if (overallString != null) { string commandNameFromEndCommand = endCommandLocation.InnerString(overallString); string commandNameFromBeginCommand = beginCommandLocation.InnerString(overallString); if (!commandNameFromBeginCommand.StartsWith(commandNameFromEndCommand)) { throw new Exception($"Commands {commandNameFromBeginCommand} and {commandNameFromEndCommand} are mismatched."); } } }
/// <summary> /// Create a toolbar separator relative to an existing command. /// </summary> /// <param name="command">The command needing a separator placed next to it.</param> /// <param name="location">Specifies the location of the separator relative to the command.</param> /// <returns>The toolbar separator pseudo-command.</returns> public static VisualRelayCommand CreateToolbarSeparator(this VisualRelayCommand command, CommandLocation location) { var separator = RootCommandGroup.ToolbarSeparatorCommand.Clone(); var delta = (location == CommandLocation.After) ? RootCommandGroup.MenuSeparatorDelta : -RootCommandGroup.MenuSeparatorDelta; separator.Weight = command.Weight + delta; separator.VisualParent = command.VisualParent; return(separator); }
/// <summary> /// 判断是否已经指定了要生成在某个位置。 /// </summary> /// <param name="value"></param> /// <returns></returns> public bool HasLocation(CommandLocation value) { return (this.Location & value) == value; }
/// <summary> /// 判断是否已经指定了要生成在某个位置。 /// </summary> /// <param name="value"></param> /// <returns></returns> public bool HasLocation(CommandLocation value) { return((this.Location & value) == value); }
/// <summary> /// Create a menu separator item relative to an existing command. /// </summary> /// <param name="command">The command needing a separator placed next to it.</param> /// <param name="location">Specifies the location of the separator relative to the command.</param> /// <param name="forAppMenu">If <c>true</c>, indicates the ribbon separator is for use in the application's ribbon /// menu, as opposed to the general ribbon toolbar.</param> /// <returns>A separator pseudo-command.</returns> public static VisualRelayCommand CreateRibbonMenuSeparator(this VisualRelayCommand command, CommandLocation location, bool forAppMenu) { var separator = RootCommandGroup.RibbonMenuSeparatorCommand.Clone(); var delta = (location == CommandLocation.After) ? RootCommandGroup.MenuSeparatorDelta : -RootCommandGroup.MenuSeparatorDelta; separator.Weight = command.Weight + delta; if (forAppMenu) { separator.MenuParent = command.MenuParent; separator.VisualParent = null; separator.UseXamlResource = false; } else { separator.MenuParent = null; separator.VisualParent = command.VisualParent; separator.UseXamlResource = RootCommandGroup.RibbonMenuSeparatorCommand.UseXamlResource; // deficiency in Clone() is that WPF-specific properties aren't cloned } separator.MenuItem = null; // reset so new menu item will always be created separator.Visual = null; // reset so new visual will always be created return(separator); }