Replies: 11 comments 16 replies
-
The relevant docs about using Avalonia without XAML are here: https://docs.avaloniaui.net/docs/data-binding/binding-from-code Those don't include basic stuff like constructing an object graph since we assume that you know what are you doing. |
Beta Was this translation helpful? Give feedback.
-
None of that stuff is actually pertinent or in any way helpful to the basic task of starting an application and creating a window. i.e. The first thing anyone would actually want to do with the library |
Beta Was this translation helpful? Give feedback.
-
I also think you misunderstood my gripe: WPF which this API is apparently based on does not have this documentation issue. The architecture is slightly different so it makes sense that it is simpler, but in WPF it is both:
It is a FAQ. That means you know this is something people have asked how to do. And even coming from WPF it wouldn't exactly be obvious how to do it in Avalonia. I am merely suggesting giving an answer in the FAQ that is actually useful to someone who is actually trying to do the frequently asked thing. My steps:
Every single step is in my opinion reasonable and logical. I have used several different GUI libraries in several different languages in over 20 years of programming. And it has literally never in my life (even when I was entirely new to programming and a literal child) taken me more than 15 minutes to get the goddamn hello world application running without 5 files and over 100 lines of code. Rant over. It is a usability issue. Period. Fix it or don't. At least if someone else has the same problem as me now, they will find this post instead of your unhelpful attitude of "we assume that you know what are you doing." GTFO with that bull. |
Beta Was this translation helpful? Give feedback.
-
Hi sorry about that, we're trying our best but we're trying as hard as we can. We don't have a team the size of some of the frameworks you may be used to using, currently and so documentation can be lacking for some use-cases (particularly if you're trying to avoid XAML). We'll try to add something to the docs about this. |
Beta Was this translation helpful? Give feedback.
-
I only have used WinForms before, it took me few days to adapt and learn the framework but almost all questions and troubles were solved by look at documentation, which is not perfect but is enough to start, more when you have that such experience... If you use Visual Studio with Avalonia extension, it's easy as create new project and select Avalonia. It will create a empty "Hello World" app for you with all requirements and things setup for you, no different from create a WinForm project. About your title question, once by random I found an library or sample that spawn a window from code without any xaml and extra files, since I was not looking for it I forgot where I saw that or the name, but then it's possible... Someone here could give you an anwser to obtain that, but your atitude isn't the best and may lead to people skip on you. |
Beta Was this translation helpful? Give feedback.
-
Hi @tseguine I'm sorry that you've found several challenges with starting development with Avalonia, and I appreciate you taking the time to let us know. We're aware that our documentation has gaps, and it's something we're keen to resolve. Our docs have been written from the perspective that developers will be writing their apps using XAML, reflecting how most of our community uses Avalonia. Given our open-source nature, the most helpful thing you could do for us (other than contribute some docs) would be to create issues in the documentation repository to let us know of missing content. Lastly, if the docs haven't helped, I suggest asking in our telegram community chat. That chat has hundreds of active Avalonia developers with a wealth of experience who can help. |
Beta Was this translation helpful? Give feedback.
-
Are the docs also in github, and are you open to pull requests? If so (and I find time: using this is for a personal project not work) I might try to write something up. |
Beta Was this translation helpful? Give feedback.
-
As a note I also ran into this exact issue — I read on the first page of the documentation that you could use it without XAML and then searched everywhere for literally any documentation on how to do it and the only thing I found was this Github issue. It's been more than two years since this was first reported, is there a canonical C# code-only example? |
Beta Was this translation helpful? Give feedback.
-
Fwiw @Dareka826 published a really helpful example here: https://github.com/Dareka826/Avalonia_no_XAML/blob/master/Program.cs using Avalonia;
using Avalonia.Controls;
class MainClass {
public static void Main(string[] args) {
AppBuilder
.Configure<Application>()
.UsePlatformDetect()
.Start(AppMain, args);
}
public static void AppMain(Application app, string[] args) {
// Application needs a theme to render window content
app.Styles.Add(new Avalonia.Themes.Simple.SimpleTheme());
app.RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Default; // Default, Dark, Light
// Create window
var win = new Window();
win.Title = "Avalonia no XAML";
win.Width = 800;
win.Height = 600;
var text = new Label();
win.Content = text;
text.Content = "Hello from C#!";
text.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
text.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
text.FontSize = 72;
win.Show();
app.Run(win);
}
} |
Beta Was this translation helpful? Give feedback.
-
I've written a set of no-XAML examples for those who are interested. There's a recommended order for helping to learn how they work, with comments in the code (the comments assume the reader is following the recommended order, so they don't repeat what's been said before). I've looked at Avalonia.Declarative.Markup, but haven't been able to understand it yet. If anyone knows of documentation on that, please post a link or let me know. It does look promising. My repo of no-XAML examples is at my GitHub page |
Beta Was this translation helpful? Give feedback.
-
I get the sense from the developers that this is considered an advanced feature and not worth it to document. That is fine, but this feature is prominently advertised on the home page. This is effectively my first foray into Avalonia. I am coming from Qt Quick with QML and Python as I would prefer building UIs with F# or at worst C# but not necessarily XAML. That this feature was advertised and F# was mentioned (!) on the homepage made me very excited and sold me immediately. However, I also found nothing in the documentation even alluding to this, which unsold me, as it makes me worry about its overall support, especially with third-party controls. I would suggest that if it is not a priority to document this, then it would be best not to advertise it on the homepage. |
Beta Was this translation helpful? Give feedback.
-
According to the FAQ it is possible to use Avalonia without xaml, but I could find almost zero information in the official documentation for how to accomplish this. Maybe I just didn't find it, but it seems like if it exists it is well hidden.
It is really frustrating from a user perspective when the only introductory way of "Getting Started" in the docs is "Hey, install this visual studio extension and download this entire project that does 1000 things you don't want or need."
I understand it is more or less the intended way of using the framework, but I don't think it is too out of line to somewhere document the 3 liner to get a basic window to display:
Application app = Application.Current ?? AppBuilder.Configure<Application>().UsePlatformDetect().SetupWithoutStarting().Instance;
app.Styles.Add(new DefaultTheme());
app.Run(new Window() { Title = "Avalonia Basic Example", Content = "Hello Avalonia!" });
As someone with no prior Avalonia, WPF, or Winforms experience it took me several hours to figure out just those three lines. And I somehow think I am not the only person whose use case fits this way of using the library better than the xaml path.
Beta Was this translation helpful? Give feedback.
All reactions