iosxamarin.iosmonotouch.dialog

MonoTouch.Dialog - How to get values out of element UI


I have a RootElement declared and set up how I want on a DialogViewController, using the element-based API rather than the reflection API. Looks great.

However I'm struggling to work out how I can get the values out. Using the reflection-based API this is easy, but I don't see how I can use BindingContext.Fetch() with an explicitly declared RootElement.

I can't find an example in the samples, nor can I work out how to do this myself.

var root = new RootElement(null){
    new Section(){
        new StringElement("Title here"),
        new FloatElement(null, null, 5f)
    }
};

var dv = new DialogViewController(root, true);

dv.ViewDisappearing += delegate {
    // what goes here to get at the value of the FloatElement?
};

NavigationController.PushViewController(dv, true);

Any help appreciated.


Solution

  • You can store it in a variable, that is scoped where your anonymous method can access it.

    Like this:

    var floatElement = new FloatElement(null, null, 5f);
    var root = new RootElement(null){
        new Section(){
            new StringElement("Title here"),
            floatElement,
        }
    };
    
    var dv = new DialogViewController(root, true);
    
    dv.ViewDisappearing += delegate {
        //You can access floatElement here
        Console.WriteLine(floatElement.Value);
    };
    
    NavigationController.PushViewController(dv, true);