c# – 我可以自定义AvalonDock上下文菜单吗?

我在项目中使用AvalonDock来利用工具窗口.

当我右键单击工具窗口标题栏时,我不需要选项卡式文档,并且想要禁用“Dock as Tabbed Document”上下文菜单项.这可能吗?

谢谢

解决方法

我认为这是一个简单的属性设置.
我使用codeplex 76560的最新资源.

您可以将DockableStyle属性更改为您想要的样式:

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

并可以覆盖此方法以禁用竞争菜单

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);
  }
}

这是标志枚举:

/// <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
}

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...