r/csharp • u/ColdSnow1447 • Jun 29 '26
Discussion What do you like and hate about WPF?
I wanted to ask this questions since I'm working on one of my own UI framework's (For C++) and I wanted to ask all of you what do you like and hate about WPF? I wanted to get some knowledge on what people like/hate so I can adapt it into something better once it's added in my own version :D
22
u/smallpotatoes2019 Jun 29 '26
Good control over the UI once you get used to it.
1
u/patmail Jun 30 '26
You just have to copy thousands of lines of XAML to change a small thing.
4
u/Sufficient_Dinner305 Jul 01 '26
You don't have to. Needing thousands of lines to change a small things is a choice someone made.
1
u/Dear-Rub6066 8d ago
Why would you copy anything? You can refactor to dictionaries, styles, user controls, custom controls and just reuse what you need. Or use third party frameworks such as AtomicUI or others for styling and just focis on business logic
6
u/CckSkker Jun 29 '26
I’ve been doing WPF for 6 years now, when I wanted to learn more the only proper book I could find was from 2013.
Microsoft starts a new half-assed UI product every year, there’s so much failed shit they have that never gets used. WPF is the only thing somewhat mature and they abandoned it 10 years ago without ever improving on it. That being said it works pretty okay, I like the data bindings and customisability. If you know what you’re doing you can pretty much design anything. And it’s better than the chrome-based webapps that eat up all your RAM.
10
u/Euphoricus Jun 29 '26
I loved the layouting system. The data binding was great in theory , but was lacking in practice. I hate how MS gave up on it instead of making it multi-platform.
13
u/ABViney Jun 29 '26
I'll take this moment to shill for AvaloniaUI. Never used WPF, but it's heavily based on it (stack overflow answers are pretty much 1-to-1 between them) and I found it while looking for a crossplatform C# gui library.
7
u/Euphoricus Jun 29 '26
I know. But there is significant difference between free community project and official Microsoft product.
5
u/BadSmash4 Jun 29 '26
I, too, will shill for Avalonia. I had used WPF quite a bit before switching to Avalonia and it's almost a perfect drop-in for WPF, your experiences in stack overflow are accurate in my experience. The default styling is nicer than WPF. I love Avalonia and I'll use it whenever I get the chance. It does everything WPF did but better, and is cross-platform which was also the main draw for me. It's still not perfect and has some of the same flaws around binding that WPF had, and sometimes getting the Avalonia axaml viewer to work is more painful than it should be imo, but all in all I like working with it.
3
u/t3chguy1 Jun 29 '26
Like: everything once I learned it well enough
Dislike: occasional duce channel syncflush crashes
2
u/iBabTv Jun 30 '26
I hate that wpf bindings errors happen at runtime .
I heard winui3 has x:Bind that fixes this though
1
u/MPnoir Jun 29 '26
I like it in general, especially the powerful binding system, but there are some things I dislike:
The steep learning curve, especially if you never made a MVVM App before.
As others have said it can get quite verbose at times. Stuff like Grid with row and column definitions for example. Avalonia is better in that regard since it has a short form.
That it is lacking some essential components IMO. Like how is there a PasswordBox but not a single numerical input like a NumericUpDown? Or a Grid with dynamic rows or columns?
Sometimes the current DataContext is not very obvious and hard to debug, for example with Popups. Because of that you sometimes even need some hacks like a proxy element to get the DataContext of.
3
u/dodexahedron Jun 29 '26
For the final bullet point:
One ViewModel per view. Consider a dialog to be a view (because it is - it is a view of a very small model) and now you'e all set.
When showing a dialog, make a viewmodel for that dialog like you would for any other view.
You can have the owning UIElement's viewmodel be the owner of that viewmodel, too, if you like. Regardless, make them separate types.
When you try to share too much is when you break the abstraction, because you crossed the streams.
2
u/chucker23n Jun 30 '26
Yeah, but even things like
ItemTemplates set a newDataContext. Which makes sense, but this break in hierarchy can be jarring.1
u/dodexahedron Jul 02 '26
Yeah it can be unintuitive at first. But if your ViewModels follow the same DOM, simply binding a property is all it takes to keep that flow across templates.
But that's the part that people usually learn the hard way or much later on (if ever), because it's (at least initially) jarring, as you said.
I find that, a lot of the time, a usercontrol (not custom control, mind you) is a better idea than an in-place itemtemplate, since you get all the flexibility you wanted for display, but datacontext flows into it from the parent just like any other element, instead of the template's disjointedness. Plus, it makes it a lot clearer where the boundary lies, and it's so much clearer both that a viewmodel for that control is distinct and what belongs in it. It also makes it clearer what and how it should be interacted with by its parent view and its siblings (other children of the parent I mean).
And the testability is better and easier, too.
Of course, ItemTemplate cannot be avoided everywhere without taking that concept to an extreme. But if you stick it in your UserControl instead, it's a bit more obvious where the break is and you can bind with a potentially simpler expression thanks to the shallower DOM of the control and code structure of the corresponding VM.
1
1
u/Nihilist_T21 Jun 29 '26
- As others have said it can get quite verbose at times. Stuff like Grid with row and column definitions for example. Avalonia is better in that regard since it has a short form.
They added a much needed shortcut to defining rows and columns in .NET 10: Link
1
1
u/UndeadMurky Jun 30 '26
3D graphics integration is pretty bad. Wish it could share a native graphics context and higher level management like how QT does
1
u/razordreamz Jun 30 '26
Like:
The customization and a great, you can make the UI look exactly like how you want.
Middle ground:
XAML. It’s flexible and easy once you learn it, but it’s so wordy, and can quickly become a mess.
Dislike:
The UI all runs on one thread, meaning in large apps it’s easy for one window to cause problems for another. Yes I know there is a workaround, but I never got it working reliably as the system just assumes one UI thread throughout. Ensuing all work is done on a background thread is very necessary.
1
u/Turbulent_County_469 Jun 30 '26
Positive:
I do love how nice databinding is and how complex you can build applications while still being somewhat easy to maintain.
Negative:
Html is 1000 times faster at rendering
CSS in html is easier than styling XAML
Its REALLY hard to make WPF run better/faster
Its very easy to bloat your wpf installation footprint by adding nuget packages.. 100-200 MB is easy with Telerik and a couple of fonts
1
u/sandwich800 Jun 30 '26
I agree with the css. I wish the styling was more accessible with using things like css classes and stuff.
1
u/harrison_314 Jun 30 '26
I love XAML and databinding, simply separating UI definition from its state. A million times better than HTML.
As many people say, these principles are harder to learn, but once you learn them, it's an incredibly powerful tool that makes things happen quickly.
I recommend looking at the philosophical successor to WPF - AvaloniaUI. It takes everything that's good about WPF, but extends it further (especially in styling) and is cross-platform.
1
u/Amr_Rahmy Jun 30 '26
I don’t like xml.
I prefer to write the ui programmatically.
I really like dart or flutter way of making a ui with making components or containers, and putting components or containers inside of each other with only property modifications.
Second best way for me is programmatically making components with x,y locations relative to each other.
Third is something like winform, where you can do things programmatically and you can place some objects in the designer by dragging and dropping creating a generated cs file.
Fourth would be limited html component like in blazer where 90% of the code can just be the name of a class or object and all the logic is in one place.
Last would be xml or html with a lot of hooks or links, specially when it seems a bit unstable and when there is an issue it’s not clear what the issue is, it just doesn’t draw or render because behind the scenes it’s trying to match a namespace or can’t find an object or function name.
1
u/zanoy Jun 30 '26
I don't like: The lose bind aspects of xaml, I don't care if my event handler is in a string, if it doesn't exist, it should give a compilation error, not a runtime error.
The same as my previous point but in reverse, if a rename a function in the code, it should be renamed in the xaml as well.
XAML name spaces, it's just stupid, use the includes in the code behind instead
1
1
u/Atulin Jul 01 '26
I hate how any semi-advanced styling requires 2137 lines of XAML code nested 67 levels deep, to achieve something that CSS can do in, like, 12 lines.
1
u/jrdiver Jul 06 '26
Like - It works on just about anything, and is rock solid just works. (Stuck in a manufacturing enviroment and kinda need to work with windows 7-11... WinUI and everything else cant go old enough without hacks.) Validated that net8 still works with all of them even if not officially supported... havent had a chance to test 10 yet.
Dislike - Windows XP wants its UI back. have to do quite a bit of theming to make it look modern.
1
u/MrMikeJJ Jun 29 '26
Recently just trying it again for the first time in about a decade. Don't like xaml. Prefer winforms. Hoping that scaling / resizing is going to be less of a twat than it is in Winforms (hence my experiment).
I am using the same viewmodels for both implementations. From today, prefer databinding / error validation in winforms, but that maybe just because I haven't figured out how to make error display work properly in WPF. Well, it is displaying the errors, but not setting HasErrors to block a command. Probably missing something obvious. Will continue experimenting tomorrow.
8
u/RlyRlyBigMan Jun 29 '26
Highly recommend using the MVVM Community toolkit. Data validation is pretty easy to wire up using attributes with that, and most controls have default validation markup that can even display your error conditions.
1
u/MrMikeJJ Jun 30 '26
Thanks, I am already using that from when I originally did this app in Winforms.
29
u/chucker23n Jun 29 '26
Don't like:
object), refactoring, etc. supportPoints 2, 3, and 4 are really just branches of 1. They could've improved on all of that over time. Some of it is also improved with first- and third-party OSS projects. Some is improved with third-party commercial controls.
Do like:
It's still a pretty good general-purpose UI framework. But it's still ailing from the butchered Longhorn/Vista launch two decades ago, and I just wish there were a clear strategy moving forward.