我是monotouch.dialog的初学者。 我试图从带有标题和值的覆盖放射性元素的radiogroup中获取一个值作为经典下拉列表!
但问题是检测事件OnSelect
MYRADIOELEMENT的代码
public class MyRadioElement : RadioElement
{
private string Caption{get; set;}
private int ID{get; set;}
public MyRadioElement(string caption, int id, NSAction selected): base(caption, id)
{
Caption = caption;
ID = id;
OnSelected += selected;
}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
base.Selected (dvc, tableView, path);
var selected = OnSelected;
if (selected != null)
selected ();
}
public event NSAction OnSelected;
}
反对者代码
var rootSex = new RootElement ("SEX",
sexUser = new RadioGroup ("", -1)){new Section ("INSERT SEX"){
from n in Def.Get_Sexes()
select (Element) new MyRadioElement (n.Descr, n.ID, ????delegate????? )}
};
我会使用委托来调用选择事件,但它会给我一个转换错误......
为什么??? 感谢
答案 0 :(得分:4)
这个应该有效
class MyRadioElement: RadioElement
{
private Action<MyRadioElement> selected;
public MyRadioElement(string caption, int id, Action<MyRadioElement> selected): base(caption, id)
{
this.selected = selected;
}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
base.Selected (dvc, tableView, path);
if (this.selected != null)
this.selected(this);
}
}
然后您将创建元素
new MyRadioElement("Caption", 2, MyMethod)
MyMethod看起来像
private void MyMethod(MyRadioElement e)
{
}