WeakEventHandler and ViewModelCommand doc/sample code

Aug 20, 2010 at 4:57 PM
Edited Aug 20, 2010 at 5:49 PM

Great initiative.

Do you have any documentation and/or sample code on how to use the WeakEventHandler and ViewModelCommand?

Coordinator
Aug 23, 2010 at 2:56 PM
This will be coming. I'm on wacation this week. Check back in a week or two.

Sent from my Windows Mobile Phone

________________________________
From: larsm <[email removed]>
Sent: Friday, August 20, 2010 9:57 AM
To: Ryan Posener <[email removed]>
Subject: WeakEventHandler and ViewModelCommand doc/sample code [slmvvms:224279]


From: larsm

Great initiative.

Do you have any documentation and/or sample code on how to use the WeakEventHandler and ViewModelCommand

Read the full discussion online<http://slmvvms.codeplex.com/Thread/View.aspx?ThreadId=224279&ANCHOR#Post482841>.

To add a post to this discussion, reply to this email ([email removed]<mailto:[email removed]?subject=[slmvvms:224279]>)

To start a new discussion for this project, email [email removed]<mailto:[email removed]>

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings<https://slmvvms.codeplex.com/subscriptions/thread/project/edit> on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

***********************************************************

This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to
whom they are addressed. If you have received this email in
error please notify the originator of the message.

IRS Circular 230 disclosure:
To ensure compliance with requirements imposed by the
IRS, we inform you that any U.S. federal tax advice contained
in this communication (including any attachments) is not
intended or written to be used, and cannot be used, for the
purpose of (i) avoiding penalties under the Internal Revenue
Code or (ii) promoting, marketing or recommending to
another party any transaction or matter addressed herein.

***********************************************************
Coordinator
Aug 29, 2010 at 8:35 PM

The example has been updated to show how this might be used in your source.  Working examples of everything are available now in the HelpDesk sample application.  Also, I have added a walkthrough in the Documentation area, which should help you understand how to get started and use this.  Also, the latest install includes a new snippet slvmnotification which handles all of the complex wiring needed to use the WeakEventHandler properly with the Notification class.

Please let me know if this does not answer your question.

Aug 30, 2010 at 2:26 PM

Thank you.

Updated sample code and new installer was very helpful.

Sep 10, 2010 at 4:01 PM
Edited Sep 10, 2010 at 4:01 PM

I added a ViewModelCommand to my ViewModel, and bound it to a button like you did in your sample. When editing directly in XAML, it all worked just fine, but when trying to Bind using VS og Blend, I got the following:

"This binding cannot be saved because it has errors. 'Unable to cast object of type "System.WeakReference" to type "System.Windows.Input.Command". 

Any ideas?

Coordinator
Sep 10, 2010 at 4:24 PM
Edited Sep 11, 2010 at 2:53 PM

One thing that I really don't understand from your question is why you would be using WeakEventHandler in a binding?  I would expect a command there. The only place I would expect a WeakEventHandler should be used is from code, not ever in a Xaml binding.  WeakEventHandler should only be used for the Notifications class.  I cannot really see any other place to use it.  If you are using it other places, you might be giving your objects too much knowledge of each other.  Between any given View, or ViewModel, they should only be aware of themselves.  Ideally the only link should be with either a Data Binding from the View to the View Model, or use the WeakEventHandler and the Notification static class from the ViewModel to send /receieve events between view models.  Using only this link prevents them from becoming dependent or having hard references to each other.  This is the key to using that tool.

Hopefully this helps.  If you still need help - please post a sample of your code where you are having problems.

Sep 11, 2010 at 9:36 PM
Edited Sep 11, 2010 at 9:37 PM

I agree with you, and I have no tight coupling in my code between View and ViewModel.

Also - when setting up the  Button Command -to-ViewModelCommand Binding in XAML, it all worked fine. So the issue was obviously in the Tooling somewhere.

Nevertheless, I have fixed the issue now. Not sure what did the trick, but i removed a couple of unused DLL's (project references) that  was sitting in my project from an earlier development cycle.

Now the all the tools (Command Binding Menu in VS and Datacontext drag/drop in Blend) works just fine....

Go figure :-)

LarsM;