3

我有一个RootElement声明并设置了我想要的方式DialogViewController,使用element-based API而不是reflection API. 看起来很棒。

但是,我正在努力弄清楚如何才能获得这些价值。使用基于反射的 API 这很容易,但我不知道如何使用BindingContext.Fetch()显式声明的RootElement.

我在示例中找不到示例,我自己也无法弄清楚如何做到这一点。

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

任何帮助表示赞赏。

4

1 回答 1

2

您可以将其存储在一个变量中,该变量的范围是您的匿名方法可以访问它。

像这样:

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);
于 2011-05-18T21:37:57.797 回答