开发者

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 Float开发者_运维知识库Element(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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜