views:

148

answers:

1

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

A: 

Hello Bruno,

I think this is a known issue with ScatterView. We are aware of the issue, and will fix it for the future. If it is the same issue we have seen, it has to do with the ItemsSource of the ScatterView being an IList<foo> or some other "generic" list. If you could change your ItemSource to be a simple IList (not an IList<foo>), I think that would resolve your issue.

I hope this helps,

-Luis Cabrera Software Design Engineer, Microsoft Surface

Luis Cabrera
The region.Views passed to the ItemsSource of the scatterview by the Prism's ItemsControlRegionAdapter class is a ViewsCollection that is a generic IEnumerable<object>. I'll test your solution by changing the Prism source and I'll let you know. Thanks
Bruno Shine

related questions