简体   繁体   English

在数据绑定的WPF窗口中浏览记录

[英]Navigating records in a databound WPF window

I'm fairly new to WPF and I've been reading many tutorials and yet while I could find many guides that showed how to bind data to textboxes and such, I couldn't find anything about navigating such data through back/forward/etc. 我是WPF的新手,我已经阅读了许多教程,但是虽然我可以找到许多指南来说明如何将数据绑定到文本框等,但是我找不到任何有关通过后退/前进/等方式导航此类数据的信息。 。 buttons. 纽扣。

This is my current situation: I have a Customer class containing data on a single customer and a Customers class which is an ObservableCollection of customer. 这是我目前的情况:我有一个Customer类,其中包含有关单个客户的数据,而Customer类是一个ObservableCollection客户。 Then data is loaded from an sqlite database (and this opens another can of worms because I don't know the exact approach for working this out but it doesn't really pertain to the current issue since I more or less got it to work) and every customer is added to the collection. 然后从sqlite数据库加载数据(这打开了另一罐蠕虫,因为我不知道解决该问题的确切方法,但是由于我或多或少使它起作用,所以它实际上与当前问题无关)并将每个客户添加到集合中。

Then in the ViewModel for the main form I have the following stuff: 然后在ViewModel的主窗体中,我有以下内容:

private Customer _objCustomer;
private Customers _customers;
private Customer _selectedCustomer;

public Customer Selection { get { return _selectedCustomer; }
        set
        {
            if (object.ReferenceEquals(value, _selectedPartecipante)) { return; }
            _selectedCustomer = value;
            base.OnPropertyChanged("Selection");
        }
    }

public Customers customers { get { return _partecipanti; }
    set { _customers = value; base.OnPropertyChanged("customers"); } }

    public Customer customer { get { return _objCustomer; } 
        set { _objCustomer = value; base.OnPropertyChanged("customer"); } }

    public string Name { get { return _objCustomer.Name; } set { _objCustomer.Name = value; base.OnPropertyChanged("Name"); } }

    public int Id { get { return _objCustomer.Id; } }

    public SubscriptionsViewModel()
    {
        _customers = Customers.LoadCustomers(); //This one loads the items from the database
        _objCustomers = _customers.First();
        _selectedCustomer = _objCustomer;
    }

This is probably wrong but I still can't find a way to fix it, what am I supposed to work to get navigation working? 这可能是错误的,但是我仍然找不到解决方法,要使导航正常工作,我应该怎么做? And how do I get the data in the current record to be saved when pressing a certain button on the form? 当按下表单上的某个按钮时,如何获取当前记录中的数据以进行保存?

Try to put the exact property in OnPropertyChanged("Customers"); 尝试将确切的属性放在OnPropertyChanged(“ Customers”);中; In your case, the property is lower case. 在您的情况下,该属性为小写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM