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

标签 c# wpf contextmenu dock avalondock

我在一个项目中使用 AvalonDock 来利用工具窗口。

我不需要选项卡式文档,并且想在右键单击工具窗口标题栏时禁用“作为选项卡式文档停靠”上下文菜单项。这可能吗?

谢谢

最佳答案

我认为这是一个简单的属性设置。 我使用来自 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
}

关于c# - 我可以自定义 AvalonDock 上下文菜单吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7959291/

相关文章:

c# - 在显示到 WPF WebBrowser 控件之前操作 HTML 文档

c# - DataGridCheckBoxColumn 在应用 ElementStyle 时丢失 IsReadOnly 状态

c# - 通过 DataContract 序列化为 XML : custom output?

c# - 在 MVVM Light 5.2.0.37222 中找不到 GalaSoft.MvvmLight.CommandWpf 命名空间

c# - 正确中止或取消 PostAsync

java - 将 java 转换为 kotlin 会中断上下文菜单

C# WPF 上下文菜单项单击事件返回 null

extjs contextmenu 单击错误 - 找不到方法......但在错误的 Controller 中查找

c# - 如果集合尚未通过比较项目的属性将项目添加到集合中?

c# - 如何在 ASP.NET 4.7.1 中报告 Prometheus-net 指标