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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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" ...
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 ...
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 ...
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 ...
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 ...
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>@...
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 ...
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
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. ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
wpf × 264c# × 140
mvvm × 103
.net × 42
design × 26
design-patterns × 26
silverlight × 13
xaml × 13
architecture × 12
winforms × 11
database × 8
entity-framework × 8
dependency-injection × 7
gui × 7
asp.net × 6
windows × 6
wcf × 6
ui × 6
unit-testing × 5
sql-server × 5
windows-8 × 5
object-oriented × 4
licensing × 4
patterns-and-practices × 4
vb.net × 4