C
C#4mo ago
Silver Black

✅ Should I use WinForms or WPF for my Windows x32 projects?

I'm an absolute beginner with .Net, VS and C#, but I've a long experience with Delphi and Windows development. So now I'm very excited with this new adventure in C#, but I'm kinda confused about what technology should I use for my Windows project... WPF or WinForms? I feel that WinForms could be the best choice. I only develop Windows native software. Thank you in advance for your help.
22 Replies
leowest
leowest4mo ago
WPF would definitively be my take here then WPF has been around for over 13+ years, it literally have documentation, tutorial and hacks to cover any issues u may encounter on top of that u have some cool $wpfuilibs to make your app looks nice out of the box without having to go around making your own controls
leowest
leowest4mo ago
now if u want to stretch it to linux, you have Avalonia that is similar to WPF
Silver Black
Silver Black4mo ago
WOW, ok thank you. From Microsoft tutorials here I thought this was the most similar to Delphi: https://learn.microsoft.com/it-it/visualstudio/get-started/csharp/tutorial-windows-forms-picture-viewer-code?view=vs-2022&tabs=csharp (it's in Italian page, sorry)
Esercitazione: Aggiungere controlli dell'interfaccia utente a un'ap...
Aggiungere controlli dell'interfaccia utente per una casella di immagini, una casella di controllo e elementi del pulsante a un'applicazione WinForms visualizzatore immagini con Visual Studio.
Silver Black
Silver Black4mo ago
What they explained seemed to me exactly what I was looking for. But form what you wrote I think I was wrong...
leowest
leowest4mo ago
winforms is easy to moc and get things done but whenever u want more complex things its a nightmare While in WPF for example:
<Grid>
<Button Content="Click Me" Click="Button_Click"/>
</Grid>
<Grid>
<Button Content="Click Me" Click="Button_Click"/>
</Grid>
Then on the code behind u would have
private void Button_Click(object sender, RoutedEventArgs e)
{

}
private void Button_Click(object sender, RoutedEventArgs e)
{

}
the above would be WPF you write your UI in xaml which is similar to xml so the only real difference is that with WPF u would be writing your controls in xml whereas in winforms u would be drag and dropping it from the toolbox for basic things that is
Silver Black
Silver Black4mo ago
Ok, now I'm starting to get it. And yes, WinForms with all the drag&drop to create GUIs is the Delphi way, that's why I was interested in that!
leowest
leowest4mo ago
also winforms use GDI while WPF uses DirectX looks like it wasn't even a question I guess more of I want to winforms, period 😛 well if u decide to try WPF I strongly recommend you do
Silver Black
Silver Black4mo ago
No no, it is a QUESTION! Because I'm starting now with C# and I want to do it the right way.
leowest
leowest4mo ago
With WPF you can do MVVM which helps a lot presenting your data to your view etc so there is a lot of things to facilitate it the benefit of learning XAML is also big sine its what new microsoft technologies use as well as Avalonia
Silver Black
Silver Black4mo ago
So even though I develop native Windows applications, system utilities, etc. do you suggest me to use WPF?
leowest
leowest4mo ago
yeah WPF is windows only UWP and WinUI3 are also windows only (these are also window only, except UWP works on xbox as well) MAUI is the crossplatform ui for microsoft unhappily it doesn't support linux all they have in common is that they use a flavor of XAML and Avalonia is a open source UI Framework that works on mobile, linux and web that looks very similar to WPF and have their flavor of XAML called AXAML and its overall very close to WPF in terms of dev
Silver Black
Silver Black4mo ago
And what about WinUI3? Should I use this? Does it use XAML too?
leowest
leowest4mo ago
Winui3 is very new so I would not advise u to use it now yes it uses slightly different flavor of XAML its just minor changes so learning WPF u will pretty much know how to use the other flavors as they dont differ that much
Silver Black
Silver Black4mo ago
Oh, ok. So I think I will start learning WPF.
leowest
leowest4mo ago
it might be a bit overwhelming at first but do give it some hours of try and anything #gui
Silver Black
Silver Black4mo ago
Thank you mate! Your advice is precious.
leowest
leowest4mo ago
you're welcome $close
MODiX
MODiX4mo ago
Use the /close command to mark a forum thread as answered
Silver Black
Silver Black4mo ago
And what about APIs? Can I use them in WPF?
leowest
leowest4mo ago
as in what? calling some web api? or are u talking about win32 api well you can use both regardless of it being wpf or console app if you're talking about web API u would be using HttpClient or a library if u prefer that would do the calls to the api and give u the result so u can use if you're talking about win32 api then u need some extra steps to define the signtura so you can then call it for example if I want to bring a app to front using the windows api SetForegroundWindow
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

Process[] processes = Process.GetProcessesByName("processname");
SetForegroundWindow(processes[0].MainWindowHandle);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

Process[] processes = Process.GetProcessesByName("processname");
SetForegroundWindow(processes[0].MainWindowHandle);
Silver Black
Silver Black4mo ago
Yes, the Win32 API. Ok, it's like Delphi with slightly different sintax.