0

Surface をいじっていて、スキャッタービューをモジュール領域として使用しようとしています。

<s:ScatterView cal:RegionManager.RegionName="{x:Static common:RegionNames.MainRegion}"></s:ScatterView>

アプリを実行すると、例外がスローされます。少し反省して、例外が発生する場所にたどり着きました。

はリージョンのDelayedRegionCreationBehavior作成を試みます。

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);
    }
}

次に、ItemsControlRegionAdapter領域ターゲットの設定を試み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;
}

scatterview は、ItemsSource の変更とItemsControlHelper呼び出されたクラスの通知を発生させます。

internal static bool IsItemsReadOnly(ItemsControl itemsControl)
{
    IList itemsControlItems = GetItemsControlItems(itemsControl);
    if (!itemsControlItems.IsReadOnly)
    {
        return itemsControlItems.IsFixedSize;
    }
    return true;
}

GetItemsControlItemsが null を返し、例外が発生したと思います。

この状況を克服する方法について何か考えはありますか?

4

1 に答える 1

0

これは ScatterView の既知の問題だと思います。私たちはこの問題を認識しており、今後修正する予定です。これが同じ問題である場合は、ScatterView の ItemsSource が IList<foo>またはその他の「一般的な」リストであることに関係しています。ItemSource を単純な IList ( IList ではない) に変更できれば<foo>、問題は解決すると思います。

これが役に立てば幸いです。

-Luis Cabrera ソフトウェア デザイン エンジニア、Microsoft Surface

于 2009-11-25T18:52:00.267 に答える