Displaying a View inside a Region is about 5-10 seconds slow for the first time, and UI freezes for that period in my Prism Composite WPF application. In subsequent times View is loaded relatively faster without any UI freezing. View is composed of a Devexpress WPF Grid control and data is fetched from a SQL database. I don't think its an issue with the Grid control / binding though, even if I remove bindings with the grid control, View takes almost same time to render itself into a Region.
This is the code I use to load View into a Region defined inside the Shell:
public Action<MenuModel> LoadViewRequest { get; set; }
public SyncController(IUnityContainer container, IEventAggregator eventAggregator, IRegionManager regionManager)
{
this.container = container;
this.eventAggregator = eventAggregator;
this.regionManager = regionManager;
this.LoadViewRequest = (menuItem) => { LoadRequestedView(menuItem); };
this.eventAggregator.GetEvent<ViewRequestedEvent>().Subscribe(LoadViewRequest, ThreadOption.UIThread, true, i => i.Module == "Sync");
}
private void LoadRequestedView(MenuModel menuItem)
{
try
{
IViewModel viewModel = this.container.Resolve<SynchronizeViewModel>();
this.regionManager.Regions["ViewRegion"].Add(viewModel.View);
this.regionManager.Regions["ViewRegion"].Activate(viewModel.View);
viewModel.DisplayName = menuItem.Description;
this.eventAggregator.GetEvent<ViewNotificationEvent>().Publish(menuItem.Description);
}
catch (ResolutionFailedException) { }
}
What could be the reason behind this behavior? Why View is getting loaded almost instantaneously when loaded for the second time? Does that mean even after removing View from the Region my application hold a reference to View?