Reputation: 35384
I have a region and want to check whether a specific view type is added to it or not. How can I do it?
Upvotes: 1
Views: 3338
Reputation: 1
object obj = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(cntrlName);
var checkIfAlreadyExists =
RegionManager.Regions["ApplicationCoreRegion"].Views.Contains(obj);
if (checkIfAlreadyExists) {
MessageBox.Show("Can not add this, because it is already shown");
} else {
RegionManager.RegisterViewWithRegion("ApplicationCoreRegion", () => obj);
RegionManager.Regions["ApplicationCoreRegion"].Activate(obj);
}
Upvotes: 0
Reputation: 3535
The following code (using Linq) should be useful:
regionManager.Regions["RegionName"].Views.Any(v => v.GetType() == typeof(ViewType));
Hope this helps,
Upvotes: 4
Reputation: 1553
You can check to see if a view has been added to a region using the following method.
var regionManager = Get reference to the region manager
bool viewHasBeenAdded = regionManager.Regions["Your region"].GetView("View Name") != null;
Is this what you want or are you actualy wanting to check for Type rather than View name?
Upvotes: 2