Click here to Skip to main content
15,898,035 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: MVVM Question Pin
lmoelleb14-Feb-11 1:47
lmoelleb14-Feb-11 1:47 
GeneralRe: MVVM Question Pin
Pete O'Hanlon14-Feb-11 5:13
mvePete O'Hanlon14-Feb-11 5:13 
GeneralRe: MVVM Question Pin
Mycroft Holmes14-Feb-11 13:36
professionalMycroft Holmes14-Feb-11 13:36 
GeneralRe: MVVM Question Pin
_Maxxx_14-Feb-11 13:58
professional_Maxxx_14-Feb-11 13:58 
GeneralRe: MVVM Question Pin
Mycroft Holmes14-Feb-11 14:06
professionalMycroft Holmes14-Feb-11 14:06 
AnswerRe: MVVM Question Pin
SledgeHammer0114-Feb-11 15:03
SledgeHammer0114-Feb-11 15:03 
GeneralRe: MVVM Question Pin
_Maxxx_14-Feb-11 17:03
professional_Maxxx_14-Feb-11 17:03 
GeneralRe: MVVM Question Pin
SledgeHammer0114-Feb-11 19:27
SledgeHammer0114-Feb-11 19:27 
_Maxxx_ wrote:
They don't need to know about each other. VM1 has a reference to some singleton - let's call it Eventor. VM2 also has a reference to Eventor (in fact, all VMs have a reference to this singleton).
VM1 tells Eventor "Please let anyone who is interested know that I just selected this Customer" and passes the customer in question (or the ID as an integer, or something to identify the customer).
Eventor has a method LetAnyoneWhoIsInterestedKnowThatThisCustomerWasSelected()
This method raises the "CustomerSelected Event.
VM2 is a subscriber to this event, and so handles it.
VM1 knows nothing of VM2 which knows nothing of VM1.

Yeah, so you need to do a lot of stuff manually (from your description -- unless I misunderstood). To me it sounds like Messenger is a more organized / compact / cleaner solution. Nobody needs to keep a ref to anything.

_Maxxx_ wrote:
Yep - I started doing this using a Messenger implementation that used strings. Trouble was I wanted to pass around an IMessenger so didn't have access to strings in the concrete Messenger class (I was,perhaps, being pedantic using IMessenger though)

In most of the frameworks I've seen, a singleton Messenger instance is exposed somewhere. What I did in mine was make it a "service" (as in the service locator pattern) and make the ServiceLocator a public static member of ViewModelBase:

IMessengerService msg = ViewModelBase.ServiceLocator.GetService<IMessengerService>();

_Maxxx_ wrote:
I think MVVM Light does, as does MVVM Foundation

I'll have to check it again. Last time I looked, I think they were strong refs, but it was a while ago, so maybe I'm confused. I looked at a lot of frameworks before I did mine.

_Maxxx_ wrote:
Not sure I follow - how do you know they're bad??

I handle the case where they throw an exception and report it. Another case is where they hang, but I don't handle that case. A possible solution might be a timeout mechanism or something.

_Maxxx_ wrote:
Not for me - I've worked on projects with big memory leak issues where events have been used across classes and have failed to be removed - over a period, memory usage can grind applications like this to a halt (in the instance to which I allude, the lookup Views failed to be garbage collected due to references kept alive by event handlers not unsubscribing)

Well, w/ messenger you'd only have that problem if something is continously being re-created and resubbing. If your views only get created once and you sub once, well, you aren't going to really "leak".

_Maxxx_ wrote:
Good point - I guess if several VMs subscribe to a message/event or whatever, firing their handlers asynchronously would be sensible in most cases - but how would you do that? One thread per handler?

I don't create seperate threads because that would make GUI calls a pain. I get the callback invocation list and enum through and call them asynchronously. In the callback completion I catch any exceptions and report / unsub them.

_Maxxx_ wrote:
Thanks, SledgeHammer, for taking the time to respond - I'd be interesting in seeing your framework if it is available for public perusal.

Sorry, its part of my "bag of tricks" assembly. Plus, I don't really have patience to support it. I figure everbody was going with mvvmlight or cinch. I just wanted to write something light weight and understand ever line of code Smile | :) . Plus it was a good way to learn mvvm Smile | :) .
GeneralRe: MVVM Question Pin
_Maxxx_14-Feb-11 23:19
professional_Maxxx_14-Feb-11 23:19 
GeneralRe: MVVM Question Pin
Pete O'Hanlon14-Feb-11 22:19
mvePete O'Hanlon14-Feb-11 22:19 
AnswerRe: MVVM Question Pin
Abhinav S14-Feb-11 18:21
Abhinav S14-Feb-11 18:21 
GeneralRe: MVVM Question Pin
_Maxxx_14-Feb-11 18:55
professional_Maxxx_14-Feb-11 18:55 
GeneralRe: MVVM Question [modified] Pin
SledgeHammer0115-Feb-11 7:31
SledgeHammer0115-Feb-11 7:31 
AnswerRe: MVVM Question Pin
BubingaMan22-Feb-11 0:05
BubingaMan22-Feb-11 0:05 
GeneralRe: MVVM Question Pin
_Maxxx_22-Feb-11 13:41
professional_Maxxx_22-Feb-11 13:41 
GeneralRe: MVVM Question Pin
BubingaMan22-Feb-11 22:04
BubingaMan22-Feb-11 22:04 
GeneralRe: MVVM Question Pin
_Maxxx_23-Feb-11 12:47
professional_Maxxx_23-Feb-11 12:47 
QuestionHow to return the value in Silverlight? [modified] Pin
Tesic Goran13-Feb-11 22:52
professionalTesic Goran13-Feb-11 22:52 
AnswerRe: How to return the value in Silverlight? Pin
Pete O'Hanlon14-Feb-11 0:32
mvePete O'Hanlon14-Feb-11 0:32 
GeneralRe: How to return the value in Silverlight? Pin
Tesic Goran14-Feb-11 0:56
professionalTesic Goran14-Feb-11 0:56 
GeneralRe: How to return the value in Silverlight? Pin
Pete O'Hanlon14-Feb-11 0:58
mvePete O'Hanlon14-Feb-11 0:58 
GeneralRe: How to return the value in Silverlight? Pin
Tesic Goran14-Feb-11 2:04
professionalTesic Goran14-Feb-11 2:04 
GeneralRe: How to return the value in Silverlight? Pin
Mycroft Holmes14-Feb-11 13:32
professionalMycroft Holmes14-Feb-11 13:32 
GeneralRe: How to return the value in Silverlight? Pin
Tesic Goran14-Feb-11 19:29
professionalTesic Goran14-Feb-11 19:29 
GeneralRe: How to return the value in Silverlight? Pin
Tesic Goran14-Feb-11 22:12
professionalTesic Goran14-Feb-11 22:12 

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.