locked
using MVVM dont know how to handle ScrollViewer_PreviewMouseWheel using Command RRS feed

  • Question

  • Hi ,

    I am newbie into MVVM trying to use but  have problem.

    i am trying to use Command for

    ScrollViewer_PreviewMouseWheel,

    i dont want to write code on View Page , so how i can do using Command.

    i dont want to use Interactive.dll also to raise event.

    Thanks

    A-


    Ashok

    Tuesday, August 28, 2012 6:23 PM

Answers

  • If you don't want to use Expression Blend's Interactive.dll EventToCommand, how about the one in MVVMLite?

    If you mean you don't want to use any 3rd party dlls, you could always make your own.

    http://code.msdn.microsoft.com/Creating-custom-Attached-5a392201  (please rate if you like ;)

    This project shows how to use attached properties to wire in and trigger a command on an event. That is essentially what EventToCommand does, using attached properties.

    In the sample, it creates a new attached event called FontSizeChanged. It also attaches an event handler for it, which in turn triggers the command.

    Regards,
    Pete


    #PEJL


    • Edited by Pete LakerMVP Tuesday, August 28, 2012 7:40 PM typo
    • Marked as answer by Sheldon _Xiao Thursday, September 6, 2012 9:20 AM
    Tuesday, August 28, 2012 7:39 PM

All replies

  • If you don't want to use Expression Blend's Interactive.dll EventToCommand, how about the one in MVVMLite?

    If you mean you don't want to use any 3rd party dlls, you could always make your own.

    http://code.msdn.microsoft.com/Creating-custom-Attached-5a392201  (please rate if you like ;)

    This project shows how to use attached properties to wire in and trigger a command on an event. That is essentially what EventToCommand does, using attached properties.

    In the sample, it creates a new attached event called FontSizeChanged. It also attaches an event handler for it, which in turn triggers the command.

    Regards,
    Pete


    #PEJL


    • Edited by Pete LakerMVP Tuesday, August 28, 2012 7:40 PM typo
    • Marked as answer by Sheldon _Xiao Thursday, September 6, 2012 9:20 AM
    Tuesday, August 28, 2012 7:39 PM
  • What do you see wrong about putting an event handler in code behind?  After all people wire up commands all the time in XAML?  What's the difference.  It's ok to write code in the view but stick to code that pertains to GUI stuff, like scrolling the scrollviewer.

    Having said that if you still want to "Bind to and Event" you could look into MVVM light:

    http://geekswithblogs.net/lbugnion/archive/2009/11/05/mvvm-light-toolkit-v3-alpha-2-eventtocommand-behavior.aspx

    I'm sure there are other ways as well, but quite frankly why worry over something so easily done in code behind of the view?


    JP Cowboy Coders Unite!

    • Proposed as answer by Sheldon _Xiao Thursday, September 6, 2012 9:20 AM
    Wednesday, August 29, 2012 2:53 AM
  • Hi ashokapex,

    I am marking your issue as "Answered", if you have new findings about your issue, please let me know, addtional, you could also use ACB, refer to this blog:

    http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 6, 2012 9:19 AM