-
Hey, Here is the code that I'm using: using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Layout;
using Avalonia.Themes.Simple;
using Dock.Avalonia.Controls;
using Dock.Model.Avalonia;
using Dock.Model.Avalonia.Controls;
using Dock.Model.Controls;
using Dock.Model.Core;
using Orientation = Avalonia.Layout.Orientation;
namespace TestAvalonia;
internal class Program
{
static void Main(string[] args)
{
AppBuilder
.Configure<App>()
.UsePlatformDetect()
.StartWithClassicDesktopLifetime(args);
}
class App : Application
{
public override void Initialize()
{
Styles.Add(new SimpleTheme());
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
}
class MainWindow : Window
{
public MainWindow()
{
Title = "Single-File Avalonia App";
Width = 400;
Height = 200;
var textBox = new TextBox { Width = 300, Margin = new Thickness(10) };
var okButton = new Button { Content = "OK", Width = 80, Margin = new Thickness(5) };
var cancelButton = new Button { Content = "Cancel", Width = 80, Margin = new Thickness(5) };
okButton.Click += (_, _) => Console.WriteLine($"Entered Text: {textBox.Text}");
cancelButton.Click += (_, _) => Close();
var factory = new MyDockFactory();
var layout = factory.CreateLayout();
factory.InitLayout(layout);
var dockControl = new DockControl()
{
Factory = factory,
Layout = layout,
InitializeFactory = true,
InitializeLayout = true,
Width = 200,
Height = 100,
};
Content = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Children =
{
dockControl,
textBox,
new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
Children = { okButton, cancelButton }
}
}
};
}
private class MyDockFactory : Factory
{
public override IRootDock CreateLayout()
{
var document = new Document
{
Id = "Document1",
Title = "My Document",
Content = new TextBlock
{
Text = "Hello, Docking!",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
}
};
var documentDock = new DocumentDock
{
Id = "DocumentsPane",
Title = "Documents",
VisibleDockables = CreateList<IDockable>(document),
ActiveDockable = document,
DefaultDockable = document
};
var rootDock = CreateRootDock();
rootDock.IsCollapsable = false;
rootDock.VisibleDockables = CreateList<IDockable>(documentDock);
rootDock.ActiveDockable = documentDock;
rootDock.DefaultDockable = documentDock;
return rootDock;
}
}
}
} Any ideas what could be misconfigured here? |
Beta Was this translation helpful? Give feedback.
Answered by
xoofx
Feb 18, 2025
Replies: 1 comment
-
It seems that's because I forgot to add styling, so the control template from Dock was not found: Styles.Add(new DockSimpleTheme()); // Add this line Then |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
xoofx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that's because I forgot to add styling, so the control template from Dock was not found:
Then
TextBlock
is now failing, but I understand why.