Home > Blockchain >  Observable Collection is not being Updated (observable collection of strings inside an observable co
Observable Collection is not being Updated (observable collection of strings inside an observable co

Time:11-09

I have 2 classes named person and Remainder

Here is the remainder class details it contains an observable collection names zuids

        public string Description;
        public DateTime DateAndTime;
        public string dateandtime;
        public bool isCompleted;
        public ObservableCollection<string> zuids;
        public string channelId;

this is the person class

 public string zuid;
        public string name,email;
        public Remainder r { get; set; }
        public Person(string id,string name,string email)
        {
            this.zuid = id;
            this.name = name;
            this.email = email;
        }

I just created this UIenter image description here

main page

public List<Person> Persons = new List<Person>();
 public List<Remainder> Remainders = new List<Remainder>();

 public ObservableCollection<Remainder> RemaindersForMe = new ObservableCollection<Remainder>();

(these remainders for me section is being displayed on the right side list of remainder in the picture)

SO here from the flyout box i have a add button which adds users to the remainder, So when i select name of some one from auto suggest box then their respective id gets updated into the remainders zuids observable collection. But when i add it is not being updated where as i tried to create the new remainder with the values of old one and the new remainders updated persons are displayed properly.

enter image description here this is the autosuggestbox here is my code

<Button Name="AddMorePeople" Content=" " CornerRadius="25" FontSize="20">
                                                        <Button.Flyout>
                                                            <Flyout>
                                                                <StackPanel >
                                                                    <AutoSuggestBox 
                                                                        Name="MyAutoSuggestBox1" 
                                                                        PlaceholderText="Search"  
                                                                        Width="150"
                                                                        SuggestionChosen="MyAutoSuggestBox1_SuggestionChosen"
                                                                        TextChanged="MyAutoSuggestBox_TextChanged"
                                                                        PointerEntered="MyAutoSuggestBox_PointerEntered"
                                                                        Tag="{x:Bind RemainderId}"
                                                                     />
                                                                </StackPanel>
                                                            </Flyout>
                                                        </Button.Flyout>
                                                    </Button>

this is the add button that is displayed in the picture, on clicking the add button an auto suggestion box opens

private void MyAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            var Auto = (AutoSuggestBox)sender;
            List<string> Suggestion;
            if (string.IsNullOrEmpty(Auto.Text))
                Suggestion = Peoplenames.Where(p=>p!="excludedname").ToList();
            else
                Suggestion = Peoplenames.Where(p => p.StartsWith(Auto.Text, StringComparison.OrdinalIgnoreCase) && p!="excludedname" ).ToList();
            Auto.ItemsSource = Suggestion.ToArray();
            
        }

private void MyAutoSuggestBox1_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            int value = (int)sender.Tag;
            
            foreach(var i in RemaindersForMe.ToList())
            {
                if(i.RemainderId==value)
                {
                    foreach(var j in Persons)
                    {
                        if(j.name==args.SelectedItem.ToString())
                        {
                            i.zuids.Add(j.zuid);
                            //Testingbox.Text = i.zuids.Count.ToString();
                            break;
                        }
                    }
                    break;
                }
            }
}

in the testing box number of users are displaying properly but it is not updated in the remianders list.

Please help Thanks in advance

CodePudding user response:

You have to use INotifyProperyChanged to reflect the changes. Also you have to use x:Bind, Mode=TwoWay.

  • Related