diff --git a/src/Avalonia.Diagnostics/DevToolsExtensions.cs b/src/Avalonia.Diagnostics/DevToolsExtensions.cs
index 4bc2ca313f..a432c94a5d 100644
--- a/src/Avalonia.Diagnostics/DevToolsExtensions.cs
+++ b/src/Avalonia.Diagnostics/DevToolsExtensions.cs
@@ -15,7 +15,7 @@ namespace Avalonia
/// The window to attach DevTools to.
public static void AttachDevTools(this TopLevel root)
{
- DevTools.Attach(root, new KeyGesture(Key.F12));
+ DevTools.Attach(root, new DevToolsOptions());
}
///
@@ -27,5 +27,15 @@ namespace Avalonia
{
DevTools.Attach(root, gesture);
}
+
+ ///
+ /// Attaches DevTools to a window, to be opened with the specified options.
+ ///
+ /// The window to attach DevTools to.
+ /// additional settint of DevTools
+ public static void AttachDevTools(this TopLevel root, DevToolsOptions options)
+ {
+ DevTools.Attach(root, options);
+ }
}
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
index 4899be2955..7942d22962 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
@@ -6,6 +6,8 @@ using Avalonia.Diagnostics.Views;
using Avalonia.Input;
using Avalonia.Interactivity;
+#nullable enable
+
namespace Avalonia.Diagnostics
{
public static class DevTools
@@ -13,12 +15,20 @@ namespace Avalonia.Diagnostics
private static readonly Dictionary s_open = new Dictionary();
public static IDisposable Attach(TopLevel root, KeyGesture gesture)
+ {
+ return Attach(root, new DevToolsOptions()
+ {
+ Gesture = gesture,
+ });
+ }
+
+ public static IDisposable Attach(TopLevel root, DevToolsOptions options)
{
void PreviewKeyDown(object sender, KeyEventArgs e)
{
- if (gesture.Matches(e))
+ if (options.Gesture.Matches(e))
{
- Open(root);
+ Open(root, options);
}
}
@@ -28,7 +38,9 @@ namespace Avalonia.Diagnostics
RoutingStrategies.Tunnel);
}
- public static IDisposable Open(TopLevel root)
+ public static IDisposable Open(TopLevel root) => Open(root, new DevToolsOptions());
+
+ public static IDisposable Open(TopLevel root, DevToolsOptions options)
{
if (s_open.TryGetValue(root, out var window))
{
@@ -38,15 +50,15 @@ namespace Avalonia.Diagnostics
{
window = new MainWindow
{
- Width = 1024,
- Height = 512,
Root = root,
+ Width = options.Size.Width,
+ Height = options.Size.Height,
};
window.Closed += DevToolsClosed;
s_open.Add(root, window);
- if (root is Window inspectedWindow)
+ if (options.ShowAsChildWindow && root is Window inspectedWindow)
{
window.Show(inspectedWindow);
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs b/src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs
new file mode 100644
index 0000000000..ee46192207
--- /dev/null
+++ b/src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs
@@ -0,0 +1,26 @@
+using Avalonia.Input;
+
+namespace Avalonia.Diagnostics
+{
+ ///
+ /// Describes options used to customize DevTools.
+ ///
+ public class DevToolsOptions
+ {
+ ///
+ /// Gets or sets the key gesture used to open DevTools.
+ ///
+ public KeyGesture Gesture { get; set; } = new KeyGesture(Key.F12);
+
+ ///
+ /// Gets or sets a value indicating whether DevTools should be displayed as a child window
+ /// of the window being inspected. The default value is true.
+ ///
+ public bool ShowAsChildWindow { get; set; } = true;
+
+ ///
+ /// Gets or sets the initial size of the DevTools window. The default value is 1024x512.
+ ///
+ public Size Size { get; set; } = new Size(1024, 512);
+ }
+}