Observable Collection 未更新(Observable collection of strings inside an observable collection of class item)

Observable Collection is not being Updated (observable collection of strings inside an observable collection of class item)

我有 2 个 classes 命名的人和 Remainder

这是剩余的 class 详细信息,它包含一个可观察的 collection names zuids

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

就是这个人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;
        }

我刚刚创建了这个 UI

主页

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

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

(我的这些remainders for me部分显示在图片右侧的remainder列表中)

所以我在弹出框中有一个添加按钮,可以将用户添加到其余部分,所以当我 select 从自动建议框中输入某个人的名字时,他们各自的 ID 会更新到剩余部分 zuids observable collection。但是当我添加它时它没有被更新,因为我试图用旧的值创建新的余数并且新的余数更新的人被正确显示。

这是自动提示框 这是我的代码

<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>

这是图片中显示的添加按钮,点击添加按钮会打开一个自动建议框

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;
                }
            }
}

测试框用户数正常显示,但在提醒列表中未更新

请帮忙 提前致谢

您必须使用 INotifyProperyChanged 来反映更改。您还必须使用 x:Bind, Mode=TwoWay.