我正在尝试使用Surface,并尝试使用scatterview作为模块区域。
<s:ScatterView cal:RegionManager.RegionName="{x:Static common:RegionNames.MainRegion}"></s:ScatterView>发生的情况是,当我运行应用程序时,抛出一个异常。稍微反思一下,我就到了异常发生的地方:
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,从而导致了异常。
对如何克服这种情况有什么想法吗?
发布于 2009-11-26 02:52:00
我认为这是ScatterView的一个已知问题。我们意识到了这个问题,并将在未来修复它。如果这是我们所看到的相同问题,那么它一定与ScatterView的ItemsSource是一个IList<foo>或其他一些“通用”列表有关。如果您可以将您的ItemSource更改为一个简单的IList (而不是IList<foo>),我认为这将解决您的问题。
我希望这能帮到你,
Microsoft Surface的-Luis Cabrera软件设计工程师
https://stackoverflow.com/questions/1796768
复制相似问题