Skip to main content
24 votes
Accepted

Is it OK to create an Entity Framework DataContext object and dispose it in a using block in each of my CRUD methods?

Use one DbContext object per data access or transaction. DbContext is a lightweight object; it is designed to be used once per business transaction. Making your DbContext a Singleton and reusing it ...
Robert Harvey's user avatar
12 votes
Accepted

Moving from Qt/C++ to C#/WPF - Productivity Gain?

I have significant experience with C++ UI development, mostly in Qt but also including wxWidgets and raw win32. I've also done some C# UI development in WPF. I would strongly recommend literally any ...
James Picone's user avatar
12 votes

Moving from Qt/C++ to C#/WPF - Productivity Gain?

Two years later, I'll add an answer myself. This purely reflects my own experience, but might help others in the same situation. Due to cross-platform availability, I didn't move to C#/WPF but rather ...
ndbd's user avatar
  • 349
11 votes

Moving from Qt/C++ to C#/WPF - Productivity Gain?

I don't have any experience with QT, but I spent over a decade working with C++ and MFC. I now have almost a decade working with C# and WPF. I find that I am an order of magnitude more productive in ...
17 of 26's user avatar
  • 4,850
11 votes
Accepted

When to use The Messenger (Mediator) Pattern in MVVM design

Those explanations are a bit confusing yes. Technically the Mediator Pattern doesn't really change anything fundamentally about the relationships between your objects. What it does do is it makes the ...
Ewan's user avatar
  • 84.4k
10 votes
Accepted

WPF UserControl Reuse With MVVM

To begin with, this answer seriously lacks theoretical support (i.e. explaining why). I would very much second this answer instead. It is much under-voted because it was posted more than a bit later. ...
Vector Zita's user avatar
  • 2,502
8 votes

How to choose NOT to use a framework (Caliburn.Micro, etc.) in a given MVVM application?

My first experience with WPF has been using Caliburn.Micro so this is probably quite different from most developers. I have found both WPF and Caliburn.Micro to be quite a steep learning curve, coming ...
human17's user avatar
  • 425
8 votes

Is it good practice to use user controls to structure WPF forms even if these user controls are only used once?

Absolutely yes. It is a good idea in the same way that it is a good idea to apply separation of concerns on classes to put each in its own in order to perform a single task. You may only have one ...
Neil's user avatar
  • 22.9k
7 votes
Accepted

How to avoid duplication of types in MVVM

CRUD operations in MVVM do seem unnecessarily redundant, don't they? But the situation changes when actual business operations are involved. Let's have a look at a different problem domain. public ...
Robert Harvey's user avatar
7 votes
Accepted

Better way than singleton pattern to ensure single instance of class

What you have written is also a singleton. Just that you throw an error when accessing it a second time. So it lacks the gloabal access to the instance, but only from the second access. So you did ...
Chris's user avatar
  • 248
6 votes
Accepted

MVVM. Is it a code smell when view model has properties with names show/hide/display that semantically belong to view?

Sometimes this can just be a naming issue. For example, calling something ShowDialog in the ViewModel when what you mean is AskTheUserForAFilePath, which is independent of how the View handles that ...
Scroog1's user avatar
  • 1,115
6 votes

C# How to avoid memory leak in this case

Why not unsubscribe when window closes? Thats normally how event aggregation works. You can also use weak references. Thats how I did in this event aggregator for a open source application public ...
Anders's user avatar
  • 671
5 votes

Duplicating Domain Model in View Model or not

MVVM tends to become a bit clunky when the application is straight forward (like the 1-1 mapping of fields you mention). The benefits come with apps of relative complexity and medium and big size. ...
John Kouraklis's user avatar
5 votes
Accepted

Where is it better to implement Copy/Cut/Paste in MVVM?

I would add a clipboard service IClipboard { void AddProgram(Program p); Program GetProgram(string id); ..... etc } and inject this into the ViewModel, which would have the copy paste ...
Ewan's user avatar
  • 84.4k
5 votes

C# WPF - Is it acceptable to have a dependency to PresentationCore.dll in domain layer?

Split the "data" and the "view": the REST side will get a binary blob which is the image in some format. Store this in an object. This goes in the data layer. The presentation ...
pjc50's user avatar
  • 15.3k
5 votes

Direct Database Access for Desktop GUI or via Application Server?

It is almost always simpler to create a central server. Normally the argument here focuses on security, that a central server makes it possible to implement fine-grained access control without having ...
amon's user avatar
  • 136k
4 votes

Is implementing INotifyPropertyChanged on a custom control a bad practice?

A Control is the View part of MVVM. What you are updating in a View is dumb info (even if you have a complex control). Generally, when you are creating a control is because: You need to render a lot ...
A Bravo Dev's user avatar
4 votes

Is it OK to create an Entity Framework DataContext object and dispose it in a using block in each of my CRUD methods?

You probably don't need to, but that doesnt mean you should never. There is a lot of advice, around the internet, and in the top rated post on this page, telling you that you "Must Not" ...
speciesUnknown's user avatar
4 votes

Is it good practice to use user controls to structure WPF forms even if these user controls are only used once?

This is a really hard question to answer without seeing the actual code. You're also mixing terms a bit. User controls are not a 1:1 mapping with ViewModels. User controls have a specific purpose ...
17 of 26's user avatar
  • 4,850
4 votes

Moving from Qt/C++ to C#/WPF - Productivity Gain?

I've been shared between WPF, Qt, JavaFX years ago, and chose WPF/c#/XAML/MVVM and find it very fast to develop, excellent to maintain, powerful in terms of possibilities and performance; it relies on ...
Soleil's user avatar
  • 143
4 votes
Accepted

Why does C# not have automatic dispatchers

why isn't it automatic and behind the scenes. This would work as long as there is only one action for one property of one component is involved, but as soon as there are more actions, maybe actions ...
Doc Brown's user avatar
  • 220k
4 votes

WPF UserControl Reuse With MVVM

The third solution you are looking for might be DependencyProperty https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-properties-overview You can use these to do all sorts of ...
Ewan's user avatar
  • 84.4k
4 votes

WPF MVVM - Pass data from child-view to parent

My prefered approach is to have a single top level view model which you bind to everything. ie, and i'm just going to use pseudocode, sorry WPF is too long winded <MainWindow> <Title>@...
Ewan's user avatar
  • 84.4k
4 votes

How can I keep accurate time in a Windows Forms (WinForms) application?

This sounds like you're in a pretty unenviable position, as you're expected to satisfy conflicting stupid requirements. First off, messing with system time is a bad idea in general, especially when ...
Hans-Martin Mosner's user avatar
3 votes

Should I build a custom text editor from scratch or enhance existing ones?

Remember, text rendering hates you and text editing hates you too. You're probably going to have hard time building your editor from scratch. I'd seriously consider extending an existing solution here
Anton Pastukhov's user avatar
3 votes

MVVM. Is it a code smell when view model has properties with names show/hide/display that semantically belong to view?

Maybe. If you were doing MVC I would say no. the purpose of the view model is to provide a model of the view which you can manipulate, query and test in code. It doesn't contain any business logic. ...
Ewan's user avatar
  • 84.4k
3 votes

Moving from Qt/C++ to C#/WPF - Productivity Gain?

I learned C#, WPF, MVVM, Entity Framework and probably some more technologies from scratch after I programmed for years with VB6, VBA, SQL and others. It was a steep learning curve and it took a long ...
Edgar's user avatar
  • 293
3 votes
Accepted

Wpf Application Structure? C#

There are two questions in there. First is about threading. When you create a new thread, it has no knowledge about UI, irrespective where or when it was created or started. So you can easily create ...
Euphoric's user avatar
  • 38.2k
3 votes

Why can’t ViewModels communicate with each other?

Views and ViewModels are meant to be reuseable components that you can combine together in different ways. If you hardcode a command on VM1 to always update VM2 then you break that reusuablity. But ...
Ewan's user avatar
  • 84.4k
3 votes

Keeping objects in RAM vs more queries to the database

Opting to load everything into memory on start up is a premature optimization. You haven't collected statistics on how long it takes to query, determined if some caching is going to speed things up ...
Berin Loritsch's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible