0
votes

I have Silverlight application using Prism and I am using a ContentControl as a region, something like below:

<ContentControl RegionManager.RegionName="Demo"/>

In some rare cases the application is throwing an exception

"This control is being associated with a region, but the control is already bound to something else".

I checked the prism library and it is throwing this error from ContentControlRegionAdapter.Adapt method. In this method it is doing following checking

if (regionTarget == null) 
    throw new ArgumentNullException("regionTarget");

bool contentIsSet = regionTarget.Content != null;
if (contentIsSet)
{
    throw new InvalidOperationException(Resources.ContentControlHasContentException);
}

In which scenario will contentIsSet be true?

Also is there any issue if I remove that condition and set the view to the content directly?

1

1 Answers

0
votes

One possible scenario

XAML

<ContentControl x:Name="mycontent" RegionManger.RegionName="MycontentRegion"/>

Codebehind

SomeView view = new SomeView();    
mycontent.Content = view;

In the above scenario you will get an error because your contentcontrol is associated with a region but somewhere in the code you set the content of the content control.