2
votes

I've upgraded an app from wp7 to 8 and am now getting a System.ArgumentException "Value does not fall within the expected range." The app throws the exception after exiting the method where I set the ItemsSource for a LongListSelector control. The StackTrace isn't available from the ExceptionObject and this works without any issues in wp7.

As a test, I have done the following in the Loaded event for the application:

 private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
        {
            List<string> test = new List<string>();
            test.Add("hi");
            BrowseListBox.ItemsSource = test;
        }

After the method is completed the exception is thrown.

Here is my XAML for the LongListSelector. The TextBlock Text properties were previously Binding but have been replaced with static values until I get this working.

<phone:LongListSelector Name="BrowseListBox" IsGroupingEnabled="True" LayoutMode="Grid">
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,0,0,17">
                                <TextBlock Text="test" TextWrapping="Wrap" FontSize="29" Tap="TextBlock_Tap_1" />
                            </StackPanel>
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                    <phone:LongListSelector.GroupHeaderTemplate>
                        <DataTemplate>
                            <Border>
                                <TextBlock Text="test" FontSize="32" Foreground="White"  />
                            </Border>
                        </DataTemplate>
                    </phone:LongListSelector.GroupHeaderTemplate>
                    <phone:LongListSelector.JumpListStyle>
                        <Style TargetType="phone:LongListSelector">
                            <Setter Property="ItemTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <Border Name="JumpListBorder" BorderThickness="0,0,0,1">
                                            <TextBlock Text="test" FontSize="50" Foreground="White"  />
                                        </Border>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </phone:LongListSelector.JumpListStyle>
                </phone:LongListSelector>

Has anyone seen this before?

3

3 Answers

8
votes

It's because you're using LayoutMode Grid

You can either not use the grid, or specify the GridCellSize property, and then it works:

<phone:LongListSelector Name="BrowseListBox" IsGroupingEnabled="True" LayoutMode="Grid" GridCellSize="50,50">
0
votes

I got these issues when attempting to Notify a property change from a Thread (async Task) the app didn't give me an error however when returning to the view I got the error you mentioned above. Using a Dispatcher solved my issue.

Deployment.Current.Dispatcher.BeginInvoke(delegate
            {
               // Do work
            });
0
votes

For me I had the same problem, did not find any solution around. I restarted my visual studio and it went away.