2011-10-31 18 views
7

Tôi đang sử dụng AvalonDock trong một dự án để tận dụng lợi thế của các cửa sổ công cụ.Tôi có thể tùy chỉnh menu ngữ cảnh AvalonDock không?

Tôi không cần bất kỳ tài liệu được gắn thẻ nào và muốn vô hiệu hóa mục menu ngữ cảnh "Dock as Tabbed Document" khi tôi nhấp chuột phải vào thanh tiêu đề của cửa sổ công cụ. Điều này có thể không?

Cảm ơn

Trả lời

3

tôi nghĩ đây là cài đặt thuộc tính đơn giản. tôi sử dụng các nguồn mới nhất từ ​​CodePlex 76560.

bạn có thể thay đổi thuộc tính DockableStyle với phong cách mà bạn muốn:

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

và có thể ghi đè phương pháp này để vô hiệu hóa các menu ngữ cảnh:

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

đây là cờ 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 
} 
+0

Cảm ơn rất nhiều, tôi đã vô hiệu hóa "Dock là tài liệu tab" một. Bạn có biết tôi cũng có thể xóa các mục và thay đổi tên hiển thị trong menu ngữ cảnh không? Tôi phát hiện một vài lỗi khi ở chế độ nổi nhưng thấy rằng thuộc tính ContextMenu của DockableContent luôn là null. –