雪崩窗口标题栏上的添加按钮可以完成吗?在上面也找不到任何资源。我已经在普通WPF窗口的标题栏上添加了按钮,但是雪崩坞没有添加按钮的选项。我有一个旧的应用程序,需要像这样在标题栏上有帮助按钮
发布于 2017-08-29 13:47:08
假设你有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;
}
但是有几个限制我没有找到解决方案:
https://stackoverflow.com/questions/45936580
复制相似问题