Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit after clarification:</strong></p> <p>It appears you don't want to use RegionManager at all, which is fine. What I would suggest then is this:</p> <p>Create an interface for your Modules to use to register view creation methods:</p> <pre><code>public interface IViewRegistry { void RegisterMainView(Func&lt;object&gt; ViewCreationDelegate); } </code></pre> <p>Your modules will use this like this:</p> <pre><code>public MyModule : IModule { IViewRegistry _registry; public MyModule(IViewRegistry registry) { _registry = registry; } public void Initialize() { _registry.RegisterMainView(() =&gt; { var vm = new MyViewModel(); var view = new MyView(); var view.DataContext = vm; return view; }); } } </code></pre> <p>Then in your shell, you first implement the view registry (this is a simplification... you'd probably want something more robust)</p> <pre><code>public ViewRegistry : IViewRegistry { public static List&lt;Func&lt;object&gt;&gt; ViewFactories { get { return _viewFactories; } } static List&lt;Func&lt;object&gt;&gt; _viewFactories = new List&lt;Func&lt;object&gt;&gt;(); public void RegisterMainView(Func&lt;object&gt; viewFactory) { _viewFactories.Add(viewFactory); } } </code></pre> <p>And lastly, here's how your shell would show that stuff. Here's its ViewModel first:</p> <pre><code>public ShellViewModel : ViewModel { public ObservableCollection&lt;object&gt; MainViews { ... } public ShellViewModel() { MainViews = new ObservableCollection&lt;object&gt;(ViewRegistry.Select(factory =&gt; factory())); } } </code></pre> <p>And here's your View (look ma, no RegionManager!):</p> <pre><code>&lt;UserControl ...&gt; &lt;Grid&gt; &lt;ItemsControl ItemsSource="{Binding MainViews}" /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>The region manager sort of attempts to give you everything I've written here, plus a lot of extensibility points, but if you don't like RegionManager or you find it doesn't fit your needs for some reason, this is how you would do this in Silverlight without it.</p> <hr> <p><strong>Further Edits:</strong></p> <p>After some more commentary from the OP, I think I understand that the OP just wants to show a view within another view without having to use RegionManager. It appears the OP is using RegionManager to show <em>every</em> view on the screen, which is probably overkill.</p> <p>The scenario I was given included an Address View and associated ViewModel being used from a different parent control. This is what I do (whether right or wrong):</p> <pre><code>&lt;UserControl x:Class="Views.MyParentView" ...&gt; &lt;StackPanel&gt; &lt;TextBlock&gt;Blah blah blah some other stuff... blah blah&lt;/TextBlock&gt; &lt;myViews:AddressView DataContext="{Binding AddressVM}" /&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>And here's the parent view's viewModel:</p> <pre><code>public ParentViewModel : ViewModel { public AddressViewModel AddressVM { ... } public ParentViewModel() { AddressVM = new AddressViewModel(); } } </code></pre> <p>That's it. This prevents you from having to work too hard to show these views. </p> <p>RegionManager is really appropriate for decoupling the parent container view from the subview, but if both of these live in the same place (same module / assembly) there is no reason to use RegionManager to show these views.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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