prismprism-7

How do I access my view from within my view model with Prism?


I'm using Prism for MVVM. In my main window, I have a ribbon menu, and a tab control which shows all of my views. I want to be able to dynamically update my ribbon with contextual commands based on which view is currently selected. The binding is more complicated than just a simple list of commands (each command has an icon, subcommands, different sizes, grouping, etc.), so I think I need to somehow get a reference to my ribbon control within the main view model so I can programatically add/configure my ribbon commands. How do I get a reference to the view from within the view model?


Solution

  • How do I get a reference to the view from within the view model?

    Use i:Interaction.Behaviors to attach the Loaded event of your view to a command on your view model and pass the view as parameter.

    And then, get mad while writing the test suites for this. If I were you, I'd do everything else before I force view types into the view model...