Note that there are some explanatory texts on larger screens.

plurals
  1. POPrism region view display on demand, how to refresh controls in active view
    primarykey
    data
    text
    <p>I am writing an application using WPF, MVVM, and PRISM regions.</p> <p>I have two regions with one view (A and B) per region. I add views to my regions in my regionmodules class as follows:</p> <pre><code> // I use the following private properties in both regionmodules.cs class private readonly IUnityContainer _container; private readonly IRegionManager _regionManager; </code></pre> <p>--A--</p> <pre><code> private void RegisterViews() { var controlsView = _container.Resolve&lt;EmulatorControlsView&gt;(); _regionManager.Regions["ControlsRegion"].Add(controlsView, "A"); } </code></pre> <p>--B--</p> <pre><code> private void RegisterViews() { var templatesView = _container.Resolve&lt;TemplatesView&gt;(); _regionManager.Regions["TemplatesRegion"].Add(templatesView, "B"); var view = _regionManager.Regions["TemplatesRegion"].GetView("B"); _regionManager.Regions["TemplatesRegion"].Deactivate(view); } </code></pre> <p>I deactivate view "B" during initialization of my app because view B overlays view A in my shell.xaml.</p> <p>A click command from view A will activate view B and deactivate view A per the following code:</p> <pre><code> private void LoadTemplateExecute() { var controlView = _regionManager.Regions["ControlsRegion"].GetView("A"); _regionManager.Regions["ControlsRegion"].Deactivate(controlView); var templateView = _regionManager.Regions["TemplatesRegion"].GetView("B"); _regionManager.Regions["TemplatesRegion"].Activate(templateView); } </code></pre> <p>Other button commands exist in my Templates region view model that Deactivates view A and Activates view B. </p> <p>This code works great, and allows me to display my views on demand. </p> <p>Problem: View B has a ListView bound to an ObservableCollection in the view model via dependency property. I currently add string items to my ObservableCollection by way of the view model constructor:</p> <pre><code> private void InitializeTemporaryLists() { TemplateList.Add("Dog"); TemplateList.Add("Cat"); TemplateList.Add("Horse"); } </code></pre> <p>However, when view B is activated, my ObservableCollection does not show the items in its list.</p> <p><em><strong>Question</em></strong>: Is there an event available in the region view or view model to notify me when the view has become active?<br> What is the best way for me to populate data to my view from the view model each time my view becomes active?</p> <p>Any ideas and code example are very much appreciated! </p> <p><strong>* Update *</strong> My ListView was not updating because I am a silly programmer. I had not declared the ObservableCollection&lt;> type in my dependency property.</p> <p>However, I am still curious to know how you smart programmers out there might handle a prism region view activation? I wish I could subscribe to an event like the following:</p> <pre><code>_regionManager.Regions["YourRegion"].OnActiveView() += HandleActiveViewEvent; </code></pre>
    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. 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