locked
Bind command to other viewmodel? RRS feed

  • Question

  • Hi,

    i have a mainview+mainviewmodel (first image) and a flyoutvview+flyoutviewmodel (left side of second image)

    when i click on the settingsbutton in the mainview, it executes the showsettingscommand and opens a new settingsview

    is it possible to bind the command from my mainviewmodel to my flyoutview or do i need to write the same command in my flyoutviewmodel and bind it to my flyoutview?

    i also have a viewmodelbase class where i have the current logged-in user

    i set the currentuser in my mainviewmodel (already working) and i need to bind the currentuser to my flyoutview (how do i do this?)

    Best Regards

    Sunday, September 18, 2016 11:37 AM

Answers

  • Hi Revooo98,

    Thank you for your post.

    >>"is it possible to bind the command from my mainviewmodel to my flyoutview"

    Yes, but you need to reset the DataContext to mainviewmodel of the button when you need to bind the command from mainviewmodel.

    >>"do i need to write the same command in my flyoutviewmodel and bind it to my flyoutview?"

    Best practice is that we bind one model for one view, so I suggest you write same command in your flyoutviewmodel. If the logic of flyoutviewmodel is independent of your view model,  you could store the command in a separated static class and it will be reused in views. For example, multi UI commands are stored in ApplicationCommands class.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by DotNet Wang Saturday, September 24, 2016 1:34 AM
    • Marked as answer by DotNet Wang Wednesday, September 28, 2016 2:15 AM
    Thursday, September 22, 2016 8:38 AM