Search This Blog

Tuesday, August 23, 2011

PRISM region in ItemsControl, Region.RegionContext is null when deleting views from region

When you delete views from your region, the RegionContext is set to null. This is probably done to
prevent memory leaks but is really frustrating at the beginning. To prevent RegionContext from being
deleted you have two options:
1) use <ContentControl as your region control. In this solution views will be replace and you won't have to delete view from region thus preventing RegionContext from being nulled
2) Clone the object that you set as RegionContext (not really a neat solution)

//delete views from your region
IViewsCollection views = regionManager.Regions[RegionNames.WorkerShowPersonalDataRegion].Views;
int count = views.Count();
foreach (var view in views)
regionManager.Regions[RegionNames.WorkerShowPersonalDataRegion].Context = new Worker(CurrentWorker);

No comments:

Post a Comment

If you like this post, please leave a comment :)