I use Prism4, and in one of my modules I try to register a view in a region, and also process its event with a button click (which is published when a user clicks a button on a view).
public class MyModule : IModule { private readonly IUnityContainer container; private readonly IRegionManager regionManager; private readonly IEventAggregator eventAggregator; public MyModule(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator) { this.container = container; this.regionManager = regionManager; this.eventAggregator = eventAggregator; eventAggregator.GetEvent<ViewAButtonClicked>().Subscribe(ViewAButtonClicked); } public void Initialize() { this.regionManager.RegisterViewWithRegion("MainRegion", typeof(ViewA));
The code above works fine, except that it does not execute the ViewAButtonClicked method.
If I switched to using another overload (commented on the code above), then everything works as expected, the ButtonClicked method works.
The description from msdn is very similar, and I'm not sure why it gave me the other behavior described above. Why does one work and one does not work when it comes to a button click event?
RegisterViewWithRegion (IRegionManager, String, Func <(Of <(Object>)>)): Associate a view with a region using a delegate to resolve the concreate instance? Look. When a region is displayed, this deluxe will be called, and the result will be added to the region's collection of views.
RegisterViewWithRegion (IRegionManager, String, Type): Link the view to the region by registering the type. When a region is displayed, this type will be resolved using ServiceLocator in a specific instance. An instance will be added to the area view collection.
source share