Note that there are some explanatory texts on larger screens.

plurals
  1. POPrism MVVM - Add child View to parent View without using Regions and Injection, just XAML
    primarykey
    data
    text
    <p>I'm fairly new to the Silverlight and the MVVM / Prism pattern so this may be a stupid question.</p> <p>I have a View which has custom controls within it. These custom controls are actually Views too and have ViewModels to drive them.</p> <p>Currently to add these 'child' Views to the View I'm using (see Fig.1) and then in the ViewModel I have an Initialise() method which resolves the child View and injects it (see Fig.2).</p> <p><strong>Fig.1</strong></p> <pre><code>&lt;UserControl x:Class="ProjectA.Module.Screens.Views.PlatformScreenView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Regions="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation" &gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;ContentControl Regions:RegionManager.RegionName="FeaturesSelectionControl" /&gt; &lt;/Grid&gt; </code></pre> <p></p> <p><strong>Fig.2</strong></p> <pre><code>public void Initialise() { IRegion featuresRegion = _regionManager.Regions["FeaturesSelectionControl"]; featuresRegion.Add(_container.Resolve&lt;IFeatureSelectionControlViewModel&gt;().View); } </code></pre> <p>My question is do I have to do this for every control I want to add? I understand why it works this way but it seems like quite a bit of code and also I need to keep track of all the region names and ensure I don't have any clashes etc. Is there a simpler way of doing this without regions and just in XAML?</p> <p>I've seen a snippet of XAML on StackOverflow <a href="https://stackoverflow.com/questions/1058124/how-can-i-bind-this-view-to-this-viewmodel">here</a> but not sure how it works and if it's what I want -</p> <pre><code>&lt;ContentControl Content="{Binding SmartFormViewModel}"/&gt; </code></pre> <p>Any help is much appreciated.</p> <p>James</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload