1

for some reason I returned to one my project in Silverlight Windows Phone 7.x

So I download VS2012 for WP and opened in past working solution. The problem is, now it's not working.

When I start debug, emulator throws me exception with text:

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)

I suppose problem is here (when I comment following code it's working)

<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>

I am not quite sure what that exception means, could somebody help me how to fix it please?

Thanks in advance

xrep
  • 185
  • 4
  • 14

1 Answers1

1

The error means that you have to define first a type of panel, before your start doing anything in your ItemPanelTemplate. The ScrollViewer derives from a Listbox and is not a Panel.

Try to add a Grid, StackPanel or Canvas around the ScrollViewer in your ItemsPanelTemplate

pazcal
  • 929
  • 5
  • 26
  • well, thx for reply but this solution gives me new exception: Cannot explicitly modify Children collection of Panel used as ItemsPanel for ItemsControl. ItemsControl generates child elements for Panel. – xrep Nov 18 '13 at 20:26
  • maybe this article can help you out? http://stackoverflow.com/questions/3131919/wrappanel-as-itempanel-for-itemscontrol – pazcal Nov 19 '13 at 06:41
  • well, figured it out, I implement that in another way, without scrollviewer around uniformgrid. Thx for your time :) – xrep Nov 19 '13 at 10:21