AvalonDock控件上的附加按钮

时间:2017-08-29 10:20:27

标签: c# wpf xaml avalondock

在avalondock windows标题栏上添加按钮是否可以完成? coudn也没有找到任何资源。我已经在普通WPF窗口的标题栏上添加了按钮,但是avalondock没有添加按钮的选项。我有一个旧的应用程序需要在标题栏上有这样的帮助按钮

need to add buttons here

1 个答案:

答案 0 :(得分:0)

假设您有DockablePane

<ad:DockingManager>
    <ad:DockablePane x:Name="myAwesomePane">
        <ad:DockableContent >
            ... SomeContent ...
        </ad:DockableContent>
    </ad:DockablePane>
</ad:DockingManager>

然后在加载窗口后,您可以在窗格可视树中找到DockPanel并为其添加按钮。

private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
    var dockPanel = FindChild<DockPanel>(myAwesomePane);
    if (dockPanel != null)
    {
        var button = new Button {Content = "Help", Margin = new Thickness(1), Width = 40};
        button.Click += (o, args) => MessageBox.Show(this, "HELP");
        DockPanel.SetDock(button, Dock.Right);
        dockPanel.Children.Insert(dockPanel.Children.Count - 1, button);
    }
}

/// <summary>
/// Find first child of given type
/// </summary>
public static T FindChild<T>(DependencyObject parent) where T : DependencyObject
{
    var childrenCount = VisualTreeHelper.GetChildrenCount(parent);

    T result = null;
    for (int i = 0; i < childrenCount; i++)
    {
        var dObj = VisualTreeHelper.GetChild(parent, i);

        result = dObj as T;
        if (result != null)
        {
            break;
        }

        result = FindChild<T>(dObj);
        if (result != null)
        {
            break;
        }
    }

    return result;
}

Help button 但是我有一些限制,我没有找到解决方案:

    窗格停靠到另一个地方后,
  • 按钮消失

  • 您必须手动为所有窗格执行此操作