Avalonia in pure C# #20585
-
|
I'm making my own programming language and I'm at the point where everything is functional and I want to add a module to build graphical applications. Of course Avalonia is practically the only choice, given that it is cross-platform. There's zero documentation on using it in pure C# instead of XAML though. It is an interpreted language so all I want is to wrap avalonia tools to my programming language functions. That includes building multiple windows, styling, etc. I did try to do something with chat gpt (again, there's no documentation elsewhere), the created window always ended up being transparent and I could not give it a solid colored background no matter what. So I'm not asking for full documentation of course, could anyone just help me set it up, have the window appear with a solid background at least lol. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
|
Avalonia didn't originally have XAML support and was completely C#. All that functionality is still there and fully supported. A number of projects leverage it. i.e. https://github.com/AvaloniaUI/Avalonia.Markup.Declarative Don't forget that XAML itself is compiled to C# as well. Documentation for this probably should be expanded over time. |
Beta Was this translation helpful? Give feedback.
-
|
Check out repros from @wieslawsoltes . He has several samples, for example https://github.com/wieslawsoltes/NXUI |
Beta Was this translation helpful? Give feedback.
-
|
@stevensrmiller created some samples, more based around rendering than UI, over at https://github.com/stevensrmiller/AvaloniaWithoutXAML I generally discourage the practice for many reasons. The only uncontested benefit, IMO, is that you stay entirely within standard .NET tooling. You will still need to learn XAML eventually because all themes (Avalonia's and third-party) have been written using XAML and you need to read the |
Beta Was this translation helpful? Give feedback.
-
|
See also this old discussion: #9006 Anyway: I don't know much about how the XAML compiler works, but I imagine you can use that with your language, assuming the language is interpreted at runtime by .NET? You can certainly load XAML at runtime already. If you are using a non ,NET language you can technically get it to work as well by using AOT. It's a bit cursed though. See this library which exposes Avalonia to Rust: https://github.com/sourcegear/bridge-info/tree/main/samples/rust/Avalonia The accompanying blog posts also explain how it works: |
Beta Was this translation helpful? Give feedback.
Avalonia didn't originally have XAML support and was completely C#. All that functionality is still there and fully supported. A number of projects leverage it. i.e. https://github.com/AvaloniaUI/Avalonia.Markup.Declarative
Don't forget that XAML itself is compiled to C# as well.
Documentation for this probably should be expanded over time.