C
C#8mo ago
koray bey

Avalonia Beginner

should I design my app in MainWindow.axaml or MainView.axaml?
36 Replies
koray bey
koray beyOP8mo ago
The document tells me to put my stuff in MainWindow but I recieve errors doing that.
SpReeD
SpReeD8mo ago
Take a look at the App.axaml.cs:
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainViewModel()
};
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = new MainView
{
DataContext = new MainViewModel()
};
}
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainViewModel()
};
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = new MainView
{
DataContext = new MainViewModel()
};
}
It should be clear what Window is used for. Maybe you start without avalonia targeting everything and concentrate on desktop dev first. It should be way easier for a beginner.
koray bey
koray beyOP8mo ago
What should I use WPF? Oh I see your point
SpReeD
SpReeD8mo ago
WPF is for Windows only
koray bey
koray beyOP8mo ago
So I can stick with avalonia? But only focus on desktop?
SpReeD
SpReeD8mo ago
Yes, depending on your goal - but for test purposes and would suggest using MVVM App targeting desktop dev, without browser/web assembly and mobile Since you mentioned WPF which is strongly bound to the MVVM pattern.
koray bey
koray beyOP8mo ago
I should proceed with WPF then switch to Avalonia?
SpReeD
SpReeD8mo ago
Are familiar with the MVVM pattern?
koray bey
koray beyOP8mo ago
Not at all.
SpReeD
SpReeD8mo ago
Are you familiar with MVC or MVP?
koray bey
koray beyOP8mo ago
No I am not familiar with any type of model patterns
SpReeD
SpReeD8mo ago
Do you wanna make a GUI program to run on windows?
koray bey
koray beyOP8mo ago
Yes
SpReeD
SpReeD8mo ago
Start with WinForms, it's event-driven and definitely easier to work and understand than WPF, Avalonia, Xamarin, Maui, etc.
koray bey
koray beyOP8mo ago
I got roasted using WinForms cause I asked a question which requires a MVVM approach Then they told me to learn WPF I am familiar with the xaml but not MVVM
SpReeD
SpReeD8mo ago
WinForms can be used with the MVVM pattern, somehow, but it's not designed to do so; WPF was designed to use it. So, for beginners, I strongly recommend starting with something that doesn't need to be build in a strict pattern. A WinForms application isn't outdated or anything, WinForms is a good, quick and still up-to-date way to design applications which concentrates on delivering results and not having fancy stylings and animations, etc.
koray bey
koray beyOP8mo ago
So why WinForms make it easier for me to learn MVVM if it isn't going to force me to use it or designed for it?
SpReeD
SpReeD8mo ago
It doesn't, it will make it easier for you to eventually have a working application
koray bey
koray beyOP8mo ago
I am somewhat experienced with WinForms but the app I am trying to make needs to use MVVM I guess
SpReeD
SpReeD8mo ago
Once you get familiar with OOP and everything related, like encapsulation, you start to learn a design-pattern, like MVVM. But the basic for any design-pattern is working in OOP rules.
koray bey
koray beyOP8mo ago
Oh thats good advice So how can I practice my OOP usage
SpReeD
SpReeD8mo ago
Why do you think it needs MVVM? - It's just a design-pattern and won't make any difference on the result of that application.
koray bey
koray beyOP8mo ago
My application has a main window and a bunch of popup windows that has their own pages, own functions which mangles with the main windows properties, since I don't know MVVM it's not my thought I asked here and they told me to go this path.
SpReeD
SpReeD8mo ago
Just my 2 cents here, make it work first, refactor later. A design-pattern is something you learn later on; first you need to get the hang of OOP. Of what you describe, WinForms is totally capable of doing so.
Kouhai
Kouhai8mo ago
I would strongly advise against using Winforms if you're not forced to use it, Avalonia is much better
koray bey
koray beyOP8mo ago
Yeah I understand your point but how do I get the hang of OOP, the apps I coded to practice my c# knowledge didn't require OOP is Avalonia harder than WPF?
Kouhai
Kouhai8mo ago
Not at all
koray bey
koray beyOP8mo ago
But just like Spreed said I don't know OOP well and Avalonia has a MVVM structure
SpReeD
SpReeD8mo ago
It is, it is for someone without any knowledge of object-oriented programming ...
Kouhai
Kouhai8mo ago
In that case I would avoid GUI applications and just build console apps, GUI adds another layer of complexity that makes it harder to learn core concepts. Well, you'd usually use MVVM with WPF as well 😅
koray bey
koray beyOP8mo ago
At which point should I decide to go GUI
Kouhai
Kouhai8mo ago
When you have a general understanding of core C# concepts, like inheritance, interfaces, Generics, LINQ You don't have to be an expert at all, but having an understanding of core concepts would make building GUI apps much easier
koray bey
koray beyOP8mo ago
Well how do I get that understanding cause normally I try to create a project using my knowledge, even though I know a bit of OOP I couldn't think of a project I would use it,(or it gets too complicated for me) what should my approach be in this kind of situations?
Kouhai
Kouhai8mo ago
Applying what you've learned by building projects is essential and you should keep doing that, but also reading official docs helps a lot of times. Now for how to approach that, if you have a project in mind, try to make it in a console application for now (because GUI adds a lot of complexity) For example if you're building a clinic app, usually you'd have a GUI, but in fact you can use a terminal UI as simple as
1. Add patient information
2. Modify patient information
3. View patient data
4. Delete patient data
5. Reports
1. Add patient information
2. Modify patient information
3. View patient data
4. Delete patient data
5. Reports
koray bey
koray beyOP8mo ago
thanks
Kouhai
Kouhai8mo ago
That doesn't mean you should keep building console apps, but until you personally feel comfortable about general concepts I would say console apps are better. And if you hit an obstacle you can always ask here in this server 👍
Want results from more Discord servers?
Add your server