none
Unable to Populate List On Pop-Up Using MVVM Light / GALASOFT

    Question

  • Hi DEVS,

    I am Working on a APP where a list has been displayed , on a list ITEM TAP a pop-up opened called Name="StoryGrid" , my problem is :

    -> I would like to populate a list on the StoryGrid , and yes I created a List and Bind Data on AllPostDetail_Collection , but Unfortunately List 'AllPostDetail_Collection'  is not being populating . 

    -> I don't know what this problem actually is ?? , becoz on my AllPostViewModel Code is working fine as I dedug at this point:

     private void SelectionChangedCommand_CallBack(object param)
            {
                AllPostDetail_Collection = new ObservableCollection<abc>();
    
                if (param != null)
                {
                        App.ViewModel = true;                    
                        for (int i = 0; i < 10; i++)
                        {
                            AllPostDetail_Collection.Add(new abc { my_text = "Text" + i });
                        }
    
                       IsVisible = Visibility.Visible;
                       //RaisePropertyChanged("AllPostDetail_Collection");
                }
                ListSelectedIndex = -1;
            } 

    and Data has been Added on AllPostDetail_Collection , but my View is unable to Populate with the Given Observable Collection ata.

    -> I'd spend more than 2 days to Rectify the Issue , but didn't get that. I have Attached my code as Sky-Drive Link and project name is School_App_1. Your any kind of Help is Requested/Appreciated.

    Regards,


    Pardeep

    Thursday, October 31, 2013 7:49 AM

All replies

  • Rather than saying new ObservableCollection have you tried just doing .Clear (assuming you have initialised it elsewhere)


    http://pauliom.wordpress.com

    Thursday, October 31, 2013 8:04 AM
  • Hi pkr2000,

    I am initializing my AllPostDetail_Collection only on :

    private void SelectionChangedCommand_CallBack(object param) {

    //----code }

    that'll called on ListBox Item Tap with Attached Command :

    public System.Windows.Input.ICommand SelectionChangedCommand {

    //----code }

    -> I think there's an issue with Datatemplate , but didn't get that .

    Regards,


    Pardeep

    Thursday, October 31, 2013 8:17 AM
  • Then don't, only initialise the collection once and use clear in the event code. You can cause problems by binding to an object that you are killing by using new.

    http://pauliom.wordpress.com

    Thursday, October 31, 2013 8:33 AM
  • Hi pkr2000,

    I code the way u are telling as , declaring the AllPostDetail_Collection like: 

    private ObservableCollection<abc> _allPostDetail_Collection;
            public ObservableCollection<abc> AllPostDetail_Collection
            {
                get
                {
                    if (_allPostDetail_Collection == null)
                        _allPostDetail_Collection = new ObservableCollection<abc>();
    
                    return _allPostDetail_Collection;
                }
                set
                {
                    if (_allPostDetail_Collection != value)
                    {
                        _allPostDetail_Collection = value;
                    }
                    RaisePropertyChanged("AllPostDetail_Collection");
                }
            } 

    and Clear the Collection Every time Tap-Event called as :

    private void SelectionChangedCommand_CallBack(object param)
            {           
                AllPostDetail_Collection.Clear();
            }

    -> But my Popup List has not been Populated Yet.  I don't know what the issue really is? can u point any other Issue in Code by just reading it??

    Regards,


    Pardeep

    Thursday, October 31, 2013 9:53 AM
  • How are you adding to the collection now?

    http://pauliom.wordpress.com

    Thursday, October 31, 2013 10:27 AM
  • Hi pkr2000,

    I am using same methods for adding items to the collection like : 

     private void SelectionChangedCommand_CallBack(object param)
            {           
                AllPostDetail_Collection.Clear();
    
                if (param != null)
                {
                        App.ViewModel = true;                    
                        for (int i = 0; i < 10; i++)
                        {
                            AllPostDetail_Collection.Add(new abc { my_text = "Text" + i });
                        }
    
                       IsVisible = Visibility.Visible;
                       //RaisePropertyChanged("AllPostDetail_Collection");
                }
                ListSelectedIndex = -1;
            }  

    -> As I Debug regularly, I found that Items has been Added to Observable Collection but view is not populating with that collection. Don't Know Anything why this is happening ??

    Regards,


    Pardeep

    Thursday, October 31, 2013 10:43 AM
  • Hi,

    I got the problem base, It is a ListSelectedIndex that has been Bind to my outer ListBox selection, what I am doing is :

    -> Set the ListSelectedIndex=-1 on outer List call-Back as :

    private void SelectionChangedCommand_CallBack(object param)
            {
                //AllPostDetail_Collection = new ObservableCollection<abc>();
                AllPostDetail_Collection.Clear();
    
                if (param != null)
                {
                        App.ViewModel = true;                    
                        for (int i = 0; i < 10; i++)
                        {
                            AllPostDetail_Collection.Add(new abc { my_text = "Text" + i });
                        }
                       IsVisible = Visibility.Visible;                 
                }
              //  ListSelectedIndex = -1;  // this was causing problem
            } 

    -> Now I set ListSelectedIndex=-1 on Hover popup hiding Event as :

     private void Hide_Popup()
            {
                IsVisible = Visibility.Collapsed;
                ListSelectedIndex = -1;
            }
     

    -> But I don't know why is this Happening becoz ListSelectedIndex bind to outer Listbox , and it Should not be put effect on Pop-up ListBox

    -> Don't know it's an Bug of MVVM or of my Code ?? Any Comment would be helpful !!

    Regards,


    Pardeep

    Thursday, October 31, 2013 11:22 AM
  • But won't that cause the whole selection chain to fire and you'll be bound to a list box with nothing selected?

    http://pauliom.wordpress.com

    Thursday, October 31, 2013 12:31 PM
  • Hi,

    Apparently I don't know it is a correct way to do or not ??  I am Confused with my Code , becoz of it's uncertain behavior. 

    -> ListSelectedIndex is bind to outer listbox but how is it reflecting on Pop-Up listbox that force it to be invisible ??

    -> I am setting ListSelectedIndex =-1 on pop-up hiding , so I am guessing it would not be thrown on my pop-up listbox.

    -> Finally I don't know any other way to Accomplish my task. So your any kind of HEED on my code would be helpful.

    Regards,


    Pardeep

    Thursday, October 31, 2013 1:10 PM