出于某种原因,我回到了Silverlight Windows Phone 7.x中的一个项目
所以我下载VS2012 for WP并在过去的工作解决方案中打开。 问题是,现在它无法正常工作。
当我开始调试时,模拟器会使用文本抛出异常:
ExceptionObject {MS.Internal.WrappedException: The ItemsControl.ItemsPanelTemplate must have a derivative of Panel as the root element. ---> System.InvalidOperationException: The ItemsControl.ItemsPanelTemplate must have a derivative of Panel as the root element.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.PivotItem.MeasureOverride(Size availableSize)
我想问题在这里(当我评论以下代码时它正在运行)
<controls:PivotItem Header="{Binding Path=LocalizedResources.Categories, Source={StaticResource LocalizedStrings}}" Margin="0,12,0,0">
<ItemsControl x:Name="_categories" ItemsSource="{Binding CategoriesVM.Categories}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ScrollViewer>
<local2:UniformGrid Rows="4" Columns="2"/>
</ScrollViewer>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Border Margin="9,0" Padding="0" BorderThickness="1" BorderBrush="White" Height="212" Width="210" Canvas.ZIndex="1">
<Image local:LowProfileImageLoader.UriSource="{Binding imgsrc}" Margin="0" Width="210" Height="210" />
</Border>
<Rectangle Width="210" Height="39" Canvas.ZIndex="2" Fill="#FF8DFFFA" VerticalAlignment="Bottom" Margin="0,0,0,10" Opacity="0.8" />
<TextBlock Text="{Binding name}" Canvas.ZIndex="4" VerticalAlignment="Bottom" Margin="25,0,0,17" Foreground="#FFCD1A1A" HorizontalAlignment="Left" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</controls:PivotItem>
我不太清楚该例外是什么意思,有人可以帮我解决这个问题吗?
提前致谢
答案 0 :(得分:1)
错误意味着在开始在ItemPanelTemplate
中执行任何操作之前,必须首先定义一种类型的面板。 ScrollViewer
来自Listbox,而非Panel。
尝试在Grid
StackPanel
附近添加Canvas
,ScrollViewer
或ItemsPanelTemplate