Data binding in Xamarin.mac

Viewed 17

I am new to the MacOS, and I am trying to rewrite some of my Windows WPF programs on a Mac.

Having read this article "https://learn.microsoft.com/en-us/xamarin/mac/app-fundamentals/databinding" I understand the basics of data binding in Xcode. (Here, an Array Controller is used to bind an NSArray to the cells of a ViewController). All this is quite clear. What I don't understand, though, is how I can alter the values of the NSArray, dynamically, so that the displayed values in the ViewController keep updating.

Is there any way of altering the values of NSArray (of of NSMutableArray), or should I be using a different class to bind to the cells of a ViewController?

Thanks.

In case it helps, the example program in the article uses a Class 'PersonModel', and the code for the ViewController class is as follows:

private NSMutableArray _people = new NSMutableArray();[Export("personModelArray")]

public NSArray People {
    get { return _people; }
}

[Export("addObject:")]
public void AddPerson(PersonModel person) {
    WillChangeValue ("personModelArray");
    _people.Add (person);
    DidChangeValue ("personModelArray");
}

[Export("insertObject:inPersonModelArrayAtIndex:")]
public void InsertPerson(PersonModel person, nint index) {
    WillChangeValue ("personModelArray");
    _people.Insert (person, index);
    DidChangeValue ("personModelArray");
}

[Export("removeObjectFromPersonModelArrayAtIndex:")]
public void RemovePerson(nint index) {
    WillChangeValue ("personModelArray");
    _people.RemoveObject (index);
    DidChangeValue ("personModelArray");
}

[Export("setPersonModelArray:")]
public void SetPeople(NSMutableArray array) {
    WillChangeValue ("personModelArray");
    _people = array;
    DidChangeValue ("personModelArray");
}
0 Answers
Related