Can I customize AvalonDock context menu?
Asked Answered
M

1

7

I am using AvalonDock in a project to take advantage of the tool windows.

I don't have any need for Tabbed Documents and would like to disable the "Dock as Tabbed Document" context menu item when I right click on a tool window title bar. Is this possible?

Thanks

Mariquilla answered 31/10, 2011 at 20:23 Comment(0)
M
3

i think this is a simple property setting. i use the latest source from codeplex 76560.

you can change the DockableStyle property to the style that you want:

<ad:SampleDockableContent DockableStyle="DockableToBorders"
                    x:Name="DockingManagerPropertiesHost"
                    Title="Only dock to borders">
</ad:SampleDockableContent>

and can override this method to disable the contect menu:

public partial class SampleDockableContent : DockableContent
{
  public SampleDockableContent() {
    this.InitializeComponent();
    this.DataContext = this;
  }

  protected override bool CanExecuteCommand(ICommand command) {
    if (command == DockableContentCommands.ShowAsDocument) {
      if (this.DockableStyle == DockableStyle.DockableToBorders) {
        return false;
      }
      if (this.State == DockableContentState.Document) {
        return false;
      }
    }
    return base.CanExecuteCommand(command);
  }
}

here is the flag enum:

/// <summary>
/// Defines how a dockable content can be dragged over a docking manager
/// </summary>
/// <remarks>This style can be composed with the 'or' operator.</remarks>
public enum DockableStyle : uint
{ 
    /// <summary>
    /// Content is not dockable at all
    /// </summary>
    None = 0x0000,

    /// <summary>
    /// Dockable as document
    /// </summary>
    Document    = 0x0001,

    /// <summary>
    /// Dockable to the left border of <see cref="DockingManager"/>
    /// </summary>
    LeftBorder  = 0x0002,

    /// <summary>
    /// Dockable to the right border of <see cref="DockingManager"/>
    /// </summary>
    RightBorder = 0x0004,

    /// <summary>
    /// Dockable to the top border of <see cref="DockingManager"/>
    /// </summary>
    TopBorder   = 0x0008,

    /// <summary>
    /// Dockable to the bottom border of <see cref="DockingManager"/>
    /// </summary>
    BottomBorder= 0x0010,

    /// <summary>
    /// A <see cref="DockableContent"/> with this style can be hosted in a <see cref="FloatingWindow"/>
    /// </summary>
    Floating = 0x0020,

    /// <summary>
    /// A <see cref="DockableContent"/> with this style can be the only one content in a <see cref="DockablePane"/> pane (NOT YET SUPPORTED)
    /// </summary>
    /// <remarks>This style is not compatible with <see cref="DockableStyle.Document"/> style</remarks>
    Single = 0x0040,

    /// <summary>
    /// A <see cref="DockableContet"/> with this style can be autohidden.
    /// </summary>
    AutoHide = 0x0080,

    /// <summary>
    /// Dockable only to a border of a <see cref="DockingManager"/>
    /// </summary>
    DockableToBorders = LeftBorder | RightBorder | TopBorder | BottomBorder | AutoHide,

    /// <summary>
    /// Dockable to a border of a <see cref="DockingManager"/> and into a <see cref="DocumentPane"/>
    /// </summary>
    Dockable = DockableToBorders | Document | Floating,

    /// <summary>
    /// Dockable to a border of a <see cref="DockingManager"/> and into a <see cref="DocumentPane"/> but not in autohidden mode (WinForms controls)
    /// </summary>
    DockableButNotAutoHidden = Dockable & ~AutoHide
}
Malefic answered 14/11, 2011 at 10:11 Comment(1)
Thanks a lot, I managed to disable the "Dock as tabbed document" one. Do you know if I can also remove items and change the name that shows up in the context menu? I spotted a couple of errors when in floating mode but found that the ContextMenu property of DockableContent is always null.Mariquilla

© 2022 - 2024 — McMap. All rights reserved.