Monotouch Dialog在委托中获取元素值

时间:2012-11-15 20:19:49

标签: xamarin.ios monotouch.dialog

我有一个从动态对象创建的rootelement。我想点击一个元素时得到对象ID:

var section = new Section("","Select a complex and then a property");
var root = new RootElement("Complexes"){section};

foreach(Complex complex in complexes){

    var line = new RootElement(complex.Name);

    foreach(Property property in complex.Properties){

        line.Add(new Section(property.Name,"Select the property to work"){

            new StringElement(property.Description, delegate {

                // NEED HELP HERE!!! here I want to get property.Id

            })
        });
    }
    section.Add(line);
}

this.Root = root;

有任何线索吗?非常感谢。

1 个答案:

答案 0 :(得分:2)

复制属性.Id在局部变量中并在委托中使用

var line = new RootElement(complex.Name);

foreach(Property property in complex.Properties){

    var propertyId = property.Id;

    line.Add(new Section(property.Name,"Select the property to work"){

        new StringElement(property.Description, delegate {

            (new UIAlertView("title", "Id - " + propertyId, null, "Ok")).Show();

        })
    });
}
section.Add(line);