Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have intermediate experience in C# and my company (am new there) is trying
to go into Mobile, so I am to figure out how to make existing apps work on WP7

I have used some tools in the Silverlight Toolkit from Codeplex, but I discovered that the forum
at codeplex is not active for a while now, so I decide to come to you guy at codeproject.

first I will like to know if I can still use Silverlight Toolkit - am skeptic on the support maybe it'll becontinued or end up like Silverlight Toolbox

Second my longlistSelector Control gives a null reference when I press the back button but changing the control to a ListBox works fine.

Please tell me what I am doing wrong and also if I have alternative to Silverlight Toolbox or if I really don't need it. I know of Coding4Fun @codeplex too. Thank you.

XAML:
<toolkit:longlistselector x:name=""areaList"" removed=""Transparent"" isflatlist=""True"<br" mode="hold" xmlns:x="#unknown" xmlns:toolkit="#unknown" />                                       ItemTemplate="{StaticResource itemTemplate}" ListHeaderTemplate="{StaticResource listHeader}" ListFooterTemplate="{StaticResource listFooter}" SelectionChanged="List_SelectionChanged" />

>


C#:
<pre lang="cs">private void List_SelectionChanged(object sender, SelectionChangedEventArgs e)
       {
           if (areaList.SelectedItem == null)
               return;
           var listbox = (ListBox)sender;
           var entry = (AreaModel)listbox.SelectedItem;
           var uri = &quot;/Territory.xaml?id=&quot; + entry.AREA_KEY;
           NavigationService.Navigate(new Uri(uri, UriKind.Relative));
           areaList.SelectedItem = null;
       }




protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
       {
           string selectedIndex = "";
           if (NavigationContext.QueryString.TryGetValue("id", out selectedIndex))
           {
               int index = int.Parse(selectedIndex);
               string strSelect = "SELECT AREA_KEY,AREA_NAME FROM AREA WHERE REGION_SK = " + index.ToString();
               _area = (Application.Current as App).db.SelectList<AreaModel>(strSelect);
               //PageTitle.Text +=
               areaList.ItemsSource = _area;
           }


HERE IS THE EXCEPTION DETAIL :
System.NullReferenceException was unhandled
  Message=NullReferenceException
  StackTrace:
       at Microsoft.Phone.Controls.LongListSelector.Balance()
       at Microsoft.Phone.Controls.LongListSelector.LongListSelector_LayoutUpdated(Object sender, EventArgs e)
       at System.Windows.FrameworkElement.OnLayoutUpdated(Object sender, EventArgs e)
       at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)
Posted
Updated 20-Jul-11 1:32am
v3
Comments
Peter_in_2780 19-Jul-11 21:22pm    
Updated tags - was just PHP (which seems totally irrelevant to me).
Mark Salsbery 19-Jul-11 21:44pm    
The Silverlight toolkits are supported, active, and you need them if you want to use any of the controls offered there since the controls there are not yet in the actual released runtime.

As for your null reference...where does this occur in the code?
darkhorse_code 20-Jul-11 7:22am    
Thank you
I recieve a null reference after press the back button, within the OnNavigateTo overrriden method. Specifically, the last line. I ravelled by the fact that this error is not there when the page is created initially, but if I try to navigate back to it, after leaving the page, it gives this error. This error does not occur if I don't override the OnNavigateTo Method OR if I just merely use the ListBox, but I just feel the ListBox is too ordinary.

I'll try to update my question with details of the error. You check it out, Please.

1 solution

well first, I would do this:

if (_area != null)


before trying to use it for anything.

Second, set the debugger setting that allows you to trace into the framework code so you can see what the LongListSelector.Balance() method is trying to do. That might steer you towards solving the problem in your code.

A simple google search for "longlistselector.balance" revealed this:

http://mikaelkoskinen.net/post/wp7-longlist-selector-problems-and-fixing-them.aspx[^]
 
Share this answer
 
Comments
[no name] 20-Jul-11 8:00am    
Excellent. My 5. Bookmarked for future reference.
darkhorse_code 20-Jul-11 10:39am    
Thank you so much your answer is very helpful. Here is the sum up
1. am sure that "_area" is not null, nevertheless I tried your suggestion and its the same issue
2. Your link was especially useful:
MIKEAL:
Overall, I recommend anyone to think twice before using the LongListSelector. The grouping-functionality is nice but in my humble opinion it’s not worth the problems the control causes.
3. There are some suggestion on codeplex I'll try them out

By the way you have been very helpful
Abhinav S 22-Jul-11 14:56pm    
Good answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900