0

I have the following object with a couple of properties:

public class Test : NSObject
{
    [Export("formattedFoo")]
    public string FormattedFoo { get { return string.Format("Test {0}", Foo); } }

    [Export("foo")]
    public string Foo { get; set; }
}

In Interface Builder, I have a text field bound to foo and a label bound to formattedFoo. Whenever the user types text into the text field, the Foo property is updated, as intended. However, the label does not get updated.

I suspect there is something I need to implement in order to communicate the dependency relationship between foo and formattedFoo to Cocoa, but I am not sure what.

Before anyone jumps in suggesting I use a formatting expression in IB, that's not really an option as the above is a vastly oversimplified example of the real-life scenario.

Michael Teper
  • 4,591
  • 2
  • 32
  • 49

1 Answers1

0

Figured it out, here are the relevant resources:

The code needs to be extended with the following method:

[Export("keyPathsForValuesAffectingFormattedFoo")]
public static NSSet GetDependenciesForFormattedFoo()
{
     return new NSSet("foo");
}

Basically, you have to have a public static method that has its name starting with "keyPathsForValuesAffecting" and ending with the name of the property that has dependencies.

Michael Teper
  • 4,591
  • 2
  • 32
  • 49