title: Loading XAML at runtime using the MVVM pattern in WPF
body: <p>This is a question that extends from the originally posted here:
  <a href="https://stackoverflow.com/questions/4077318/loading-xaml-xml-through-runtime/4077786#4077786">Link to loading-xaml through runtime</a></p>
  
  <p>I'm working on a WPF MVVM application that loads XAML content dynamically from an external source, very similar as the answer in the post above.<br>
  Here is what I got so far:</p>
  
  <ol>
  <li>My View declares an instance of the ViewModel as a resource and creates an instance of that ViewModel</li>
  <li>In my ViewModel constructor I'm loading a XamlString property coming from an external source (file or db..)</li>
  <li>In my view I have a button that user clicks after ViewModel finishes loading and in the click-event code-behind I'm deserializing the dynamically loaded XAML and add it to my grid.</li>
  </ol>
  
  <p>My question is, how can I eliminate code-behind and automate the logic so the View can render the new xaml section dynamically right after the ViewModel is done getting the XAML content and initializing the string property?</p>
  
  <p>Should I use some kind of Messaging Bus so the ViewModel notifies once the property has been set so the View can add the new content? </p>
  
  <p>What troubles me is the fact that ViewModels do have a reference to Views and should not be in charge of generating UI elements.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Edit</strong>:
  Just to clarify: in my particular case I am not trying to bind a Business Object or Collection (Model) to a UI element (e.g. Grid) which obviously could be accomplished through templates and binding. My ViewModel is retrieving a whole XAML Form from an external source and setting it as a string property available to the View.<br><br> My question is: Who should be in charge of deserializing this XAML string property into a UI element and add it programmatically to the my grid once my Xaml string property in the VM is set?<br> 
  This sounds to me more of like a View responsibility, not ViewModel. But the pattern as i understand it enforces to replace any code-behind logic with V-VM bindings. </p>