无法获取 NotifyPropertyChanged 集合上的数据更新

发布于 2024-12-18 02:08:22 字数 1178 浏览 4 评论 0原文

我正在构建一个 Mango 应用程序,将数据写入 SqlCe 数据库;我有一个绑定到 DataSourceListBox ,该数据源在添加到数据库时必须显示项目,但是当我添加/更新数据时,我无法获取更新,并且仅显示它们当我重新加载页面时。 以下是一些片段:

public class TimeTrackerViewModel: INotifyPropertyChanged, INotifyPropertyChanging
{
    private List<TimeItems> _timeItems;
    public List<TimeItems> TimeItems
    {
        get { return _timeItems; }
        set
        {
            NotifyPropertyChanging("TimeItems");
            _timeItems = value;
            NotifyPropertyChanged("TimeItems");
        }
    }

    public void LoadCollectionsFromDatabase()
    {

        // Specify the query for all to-do items in the database.
        var times = from t in db.Times
                    select new TimeItems
                    {
                        DtIn = t.DtIn,
                        DtOut = t.DtOut,
                        Id = t.Id
                    };


        // Query the database and load all to-do items.
        TimeItems = new List<TimeItems>(times);
    }
.....
.....
}

当我将数据添加到 Times 表时,我没有看到绑定到 TimeItems 集合的 listBox 的数据库更新。 我做错了什么?

I'm building a Mango app that writes data to a SqlCe database; I have a ListBox bound to a DataSource that must show items when they are added to the database, but when I add/update data I cannot get updates and they are only shown when I reload the page.
Here are some snippets:

public class TimeTrackerViewModel: INotifyPropertyChanged, INotifyPropertyChanging
{
    private List<TimeItems> _timeItems;
    public List<TimeItems> TimeItems
    {
        get { return _timeItems; }
        set
        {
            NotifyPropertyChanging("TimeItems");
            _timeItems = value;
            NotifyPropertyChanged("TimeItems");
        }
    }

    public void LoadCollectionsFromDatabase()
    {

        // Specify the query for all to-do items in the database.
        var times = from t in db.Times
                    select new TimeItems
                    {
                        DtIn = t.DtIn,
                        DtOut = t.DtOut,
                        Id = t.Id
                    };


        // Query the database and load all to-do items.
        TimeItems = new List<TimeItems>(times);
    }
.....
.....
}

When I add data to the Times table I don't see db updates to the listBox bound to the TimeItems collection.
What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-12-25 02:08:22

TimeItems 设为 ObservableCollection

Make TimeItems an ObservableCollection

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文