Hi all. I'm playin around with Surface and I'm trying to use a scatterview as a module region.
<s:ScatterView cal:RegionManager.RegionName="{x:Static common:RegionNames.MainRegion}"></s:ScatterView>
What happens is that when I run the app, a exception is thrown. With a litle reflection I got to the place where the exception occours:
The DelayedRegionCreationBehavior tries to create the region:
protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)
{
try
{
// Build the region
IRegionAdapter regionAdapter = this.regionAdapterMappings.GetMapping(targetElement.GetType());
IRegion region = regionAdapter.Initialize(targetElement, regionName);
return region;
}
catch (Exception ex)
{
throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, Resources.RegionCreationException, regionName, ex), ex);
}
}
Then the ItemsControlRegionAdapter attemps to the set region target ItemsSource:
protected override void Adapt(IRegion region, ItemsControl regionTarget)
{
bool itemsSourceIsSet = regionTarget.ItemsSource != null;
#if !SILVERLIGHT
itemsSourceIsSet = itemsSourceIsSet || (BindingOperations.GetBinding(regionTarget, ItemsControl.ItemsSourceProperty) != null);
#endif
if (itemsSourceIsSet)
{
throw new InvalidOperationException(Resources.ItemsControlHasItemsSourceException);
}
// If control has child items, move them to the region and then bind control to region. Can't set ItemsSource if child items exist.
if (regionTarget.Items.Count > 0)
{
foreach (object childItem in regionTarget.Items)
{
region.Add(childItem);
}
// Control must be empty before setting ItemsSource
regionTarget.Items.Clear();
}
regionTarget.ItemsSource = region.Views;
}
The scatterview fires a notification of the ItemsSource change and class the ItemsControlHelper is called :
internal static bool IsItemsReadOnly(ItemsControl itemsControl)
{
IList itemsControlItems = GetItemsControlItems(itemsControl);
if (!itemsControlItems.IsReadOnly)
{
return itemsControlItems.IsFixedSize;
}
return true;
}
I think that the GetItemsControlItems return null, causing the exception.
Any thoughts on how to overcome this situation? Thanks.
Bruno