Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6698063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:32:00+00:00 2026-05-26T06:32:00+00:00

Windows Phone 7.1: How to add/delete items from LongListSelector control? I am using a

  • 0

Windows Phone 7.1: How to add/delete items from LongListSelector control?

I am using a LongListSelector control from ‘Windows Phone Toolkit’. The control is data bound to a ViewModel inherited from an ObservableCollection. When I try the following code:

MyObject mo = new MyObject("Name", "Description", "Value");
App.MyObjectsViewModel.Add(mo);

The ViewModel does seem to get updated but the LongListSelector does not update? What am I missing?

PS: I am new to Silverlight and WP7 development.

Following the XAML for the LongListSelector and the DataTemplates. The code is pretty much straight out of the Windows Phone Toolkit sample (removed some formatting related code to keep the post small)

<DataTemplate x:Key="groupHeader">
    <TextBlock Text="{Binding Key}"/>
</DataTemplate>

<DataTemplate x:Key="groupItemHeader">
    <Border>
        <TextBlock Text="{Binding Key}" 
           Foreground="#FFFFFF" 
           FontSize="{StaticResource PhoneFontSizeLarge}"/>
        </Border>
</DataTemplate>

<DataTemplate x:Key="myobjectItemTemplate">
    <Grid>     
    <StackPanel VerticalAlignment="Top" Orientation="Vertical">
        <TextBlock Text="{Binding Symbol}"/>
        <TextBlock Text="{Binding Value}"/>
        <TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
    </StackPanel>
    </Grid>
</DataTemplate>

<controls:PivotItem Header="myobjects">
<toolkit:LongListSelector x:Name="myobjectsList" 
    Background="Transparent"
    GroupHeaderTemplate="{StaticResource groupHeader}"
    GroupItemTemplate="{StaticResource groupItemHeader}"
    ItemTemplate="{StaticResource myobjectItemTemplate}"
    GroupViewOpened="LongListSelector_GroupViewOpened"
    GroupViewClosing="LongListSelector_GroupViewClosing"/>
</controls:PivotItem>

C# code behind for setting the ItemSource

var myobjectsByClassification = from myobjects in App.MyObjectsLibrary
        group myobjects by myobjects.Classification into c
        orderby c.Key
        select new PublicGrouping<string, MyObject>(c);

this.myobjectsList.ItemsSource = myobjectsByClassification;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:32:01+00:00Added an answer on May 26, 2026 at 6:32 am

    My guess is that the grouping code is only being called once somewhere in code behind. So the grouped collection is not updated when you add something to your ViewModel collection. The easiest way to handle this (but maybe not the most elegant) is to create your own AddItem() method for the ViewModel collection.

    class MyViewModelObject
    {
      void AddItem( MyObject obj )
      {
        App.MyObjectsLibrary.Add( obj );
        MyObjectsByClassification = from myobjects in App.MyObjectsLibrary
                                    group myobjects by myobjects.Classification into c
                                    orderby c.Key
                                    select new PublicGrouping<string, MyObject>(c);
      }
    }
    

    Bind MyObjectsByClassification to LongListSelector.ItemsSource in XAML, and make sure you notify the LongListSelector of changes to the property by using INotifyPropertyChanged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got VS2010 installed, I've downloaded the Windows Phone add-in and the Silverlight Toolkit
I want add to my Windows phone app masked textbox, are there ready-made control
In Windows phone we can store and retrieve anything using IsolatedStorageSettings.ApplicationSettings.Add(foo, bar); IsolatedStorageSettings.ApplicationSettings[foo] Then
I am developing the Windows Phone 7, I need to add images to ListBox.
How can I add and remove icons in the application bar on windows phone
In Windows Phone (mango) I am using Microsoft.Phone.Controls.Maps. I currently have: var _City =
i was reading a tutorial for windows phone 7 using C# and sliverlight and
On Windows Phone 7, go to Settings, email & accounts, add an account, the
I'm developing my first Windows Phone 7 application and I have to add an
I am a newbie in windows phone 7. WHen I add a new windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.