Item does not automatic add to list

4 posts, 1 answers
  1. Joshua
    Joshua avatar
    5 posts
    Member since:
    May 2014

    Posted 30 May 2014 Link to this post

    Hi,
    I'm trying to add new item to DataBoundListBox but it's just showing "Loading" :
    This is my code :

     public partial class Page1 : PhoneApplicationPage
    {
        // Constructor

        List<Employee> listEmployee = new List<Employee>()
        {
             new Employee(){Name = "John",Age = 24, ImgUrl = "1.jpg",Company = "MICROSOFT"},
             new Employee(){Name = "Smith",Age = 30, ImgUrl = "2.jpg",Company = "MICROSOFT"},
             new Employee(){Name = "Brown",Age = 35, ImgUrl = "3.jpg",Company = "MICROSOFT"},
             new Employee(){Name = "Taylor",Age = 33, ImgUrl = "4.jpg", Company = "MICROSOFT"},
        };

        public Page1()
        {
            InitializeComponent();
            lstEmployee.ItemsSource = listEmployee;
            lstEmployee.DataVirtualizationMode = Telerik.Windows.Controls.DataVirtualizationMode.OnDemandAutomatic;
            lstEmployee.DataRequested += this.OnDataRequested;
        }

        private void OnDataRequested(object sender, EventArgs args)
        {
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
            listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });

        }
    }
  2. Joshua
    Joshua avatar
    5 posts
    Member since:
    May 2014

    Posted 30 May 2014 Link to this post

    This is my XAML :
    <telerikPrimitives:RadDataBoundListBox Name="lstEmployee">
                    <telerikPrimitives:RadDataBoundListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"  />
                                    <ColumnDefinition Width="*"  />
                                </Grid.ColumnDefinitions>
                                <TextBlock Margin="10" VerticalAlignment="Center" Text="{Binding Name}" FontSize="30" Grid.Column="1"></TextBlock>
                            </Grid>
                        </DataTemplate>
                    </telerikPrimitives:RadDataBoundListBox.ItemTemplate>
                </telerikPrimitives:RadDataBoundListBox>
  3. DevCraft banner
  4. Answer
    Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    661 posts

    Posted 30 May 2014 Link to this post

    Hi Joshua,

    In this case the problem is that the RadDataBoundListbox.ItemsSource is of type List<T> which does not implement the INotifyCollectionChanged interface and the RadDataBoundListBox is not notified about the new items that have been added. If you use ObservableCollection<T> instead, everything should work as expected.

    Let me know how it goes.


    Regards,
    Ivaylo Gergov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Joshua
    Joshua avatar
    5 posts
    Member since:
    May 2014

    Posted 30 May 2014 in reply to Ivaylo Gergov Link to this post

    Hi,
    It works now.
Back to Top
DevCraft banner