Click here to Skip to main content
15,887,404 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Expander Style Question Pin
Abhinav S17-Nov-10 20:58
Abhinav S17-Nov-10 20:58 
QuestionHyperlink layout question Pin
CrafterIt16-Nov-10 23:42
CrafterIt16-Nov-10 23:42 
AnswerRe: Hyperlink layout question Pin
Abhinav S17-Nov-10 0:28
Abhinav S17-Nov-10 0:28 
GeneralRe: Hyperlink layout question Pin
CrafterIt17-Nov-10 0:54
CrafterIt17-Nov-10 0:54 
QuestionMVVM FolderBrowserDialog Pin
eddieangel15-Nov-10 13:23
eddieangel15-Nov-10 13:23 
AnswerRe: MVVM FolderBrowserDialog Pin
SledgeHammer0115-Nov-10 13:32
SledgeHammer0115-Nov-10 13:32 
GeneralRe: MVVM FolderBrowserDialog Pin
eddieangel15-Nov-10 13:59
eddieangel15-Nov-10 13:59 
GeneralRe: MVVM FolderBrowserDialog Pin
SledgeHammer0115-Nov-10 14:47
SledgeHammer0115-Nov-10 14:47 
MVVM *IS* pomp & circumstance. Most things you can do "the old way" in 1/10th the code and 1/10th the time that it'll take you in MVVM. You don't need to use it. You can write a WPF app just fine "the old way".

Since you mentioned a FolderBrowserDialog, I'll use that as an example of why MVVM is "teh awes0me!" Smile | :) .

The Old Way: Lets say you have a dialog with a button on it. The button launches the FolderBrowserDialog. You've just rendered the entire window and all the code involved "untestable". If you try to run a unit test and happen to run down the path that pops up the FolderBrowserDialog, no one will be there to select a file and thus your unit tests will fail.

Normally, your "infrastructure" code will be unit testable and your GUI code will not be.

MVVM splits that up. So now your infrastructure code is unit testable AND about "most" of your GUI code is as well.

The ServiceLocator helps solve part of that problem.

Lets say your code is littered with:

FileDialog fd = new FileDialog();
fd.Browse();
... fd.SelectedFile;

you can't unit test that... but with a service locator, you can... now instead of having that code everywhere, you'd do:

IDialogService svc = ViewModelBase.ServiceLocator.GetService<IDialogService>();
svc.ShowFileDialog();

How will that help?

Well, under normal circumstances, you would have a REAL IDialogService and ShowFileDialog() would call FileDialog fd = new FileDialog();, etc...

but when you are doing unit tests, you would register a dummy IDialogService, in this version, ShowFileDialog() would simply be hardcoded to return "c:\\dummy.txt".

You haven't changed any application code at all and now you can unit test.

Makes sense?

Thats just a basic example, but thats the general concept behind the service locator pattern.

If you don't care about unit testing and you are working on the code by yourself, I'd skip MVVM. If you are required to do unit tests, MVVM and ServiceLocator will work well.

In general, MVVM will produce cleaner WPF code (once you get your pomp & circumstance code in place Smile | :) ).
GeneralRe: MVVM FolderBrowserDialog Pin
eddieangel16-Nov-10 6:10
eddieangel16-Nov-10 6:10 
AnswerRe: MVVM FolderBrowserDialog Pin
Abhinav S16-Nov-10 4:54
Abhinav S16-Nov-10 4:54 
GeneralRe: MVVM FolderBrowserDialog Pin
eddieangel16-Nov-10 6:05
eddieangel16-Nov-10 6:05 
GeneralRe: MVVM FolderBrowserDialog Pin
SledgeHammer0116-Nov-10 7:04
SledgeHammer0116-Nov-10 7:04 
GeneralRe: MVVM FolderBrowserDialog Pin
eddieangel16-Nov-10 7:11
eddieangel16-Nov-10 7:11 
GeneralRe: MVVM FolderBrowserDialog Pin
SledgeHammer0116-Nov-10 9:09
SledgeHammer0116-Nov-10 9:09 
AnswerRe: MVVM FolderBrowserDialog Pin
Kevin Marois17-Nov-10 5:24
professionalKevin Marois17-Nov-10 5:24 
GeneralRe: MVVM FolderBrowserDialog Pin
SledgeHammer0117-Nov-10 9:47
SledgeHammer0117-Nov-10 9:47 
GeneralRe: MVVM FolderBrowserDialog Pin
Kevin Marois17-Nov-10 11:14
professionalKevin Marois17-Nov-10 11:14 
GeneralRe: MVVM FolderBrowserDialog Pin
SledgeHammer0117-Nov-10 12:31
SledgeHammer0117-Nov-10 12:31 
GeneralRe: MVVM FolderBrowserDialog Pin
Pete O'Hanlon17-Nov-10 10:00
mvePete O'Hanlon17-Nov-10 10:00 
GeneralRe: MVVM FolderBrowserDialog Pin
_Maxxx_17-Nov-10 16:11
professional_Maxxx_17-Nov-10 16:11 
GeneralRe: MVVM FolderBrowserDialog Pin
Pete O'Hanlon17-Nov-10 21:50
mvePete O'Hanlon17-Nov-10 21:50 
QuestionDataGrid - merging cells Pin
urinspiration15-Nov-10 7:41
urinspiration15-Nov-10 7:41 
QuestionWPF Style Question Pin
Kevin Marois15-Nov-10 7:08
professionalKevin Marois15-Nov-10 7:08 
AnswerRe: WPF Style Question Pin
#realJSOP15-Nov-10 8:03
mve#realJSOP15-Nov-10 8:03 
GeneralRe: WPF Style Question Pin
Kevin Marois15-Nov-10 8:05
professionalKevin Marois15-Nov-10 8:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.