开发者

Using scatterview as a region with Prism throws an exception

I'm playing 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 开发者_如何学CRegionCreationException(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 returns null, causing the exception.

Any thoughts on how to overcome this situation?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜