MonoTouch.Dialog:响应RadioGroupselect

我有一个由MonoTouch.Dialog创build的对话框。 有一个广播组的医生名单:

Section secDr = new Section ("Dr. Details") { new RootElement ("Name", rdoDrNames){ secDrNames } 

一旦select了医生,我希望更新代码中的Element 。 被选中RadioElement的最佳方式是什么?

创build你自己的RadioElement如:

 class MyRadioElement : RadioElement { public MyRadioElement (string s) : base (s) {} public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { base.Selected (dvc, tableView, path); var selected = OnSelected; if (selected != null) selected (this, EventArgs.Empty); } static public event EventHandler<EventArgs> OnSelected; } 

注意:如果您想要有多个无线电组,请不要使用静态事件

然后创build一个使用这个新types的RootElement ,如:

  RootElement CreateRoot () { StringElement se = new StringElement (String.Empty); MyRadioElement.OnSelected += delegate(object sender, EventArgs e) { se.Caption = (sender as MyRadioElement).Caption; var root = se.GetImmediateRootElement (); root.Reload (se, UITableViewRowAnimation.Fade); }; return new RootElement (String.Empty, new RadioGroup (0)) { new Section ("Dr. Who ?") { new MyRadioElement ("Dr. House"), new MyRadioElement ("Dr. Zhivago"), new MyRadioElement ("Dr. Moreau") }, new Section ("Winner") { se } }; } 

[UPDATE]

这是RadioElement的一个更现代的版本:

 public class DebugRadioElement : RadioElement { Action<DebugRadioElement, EventArgs> onCLick; public DebugRadioElement (string s, Action<DebugRadioElement, EventArgs> onCLick) : base (s) { this.onCLick = onCLick; } public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { base.Selected (dvc, tableView, path); var selected = onCLick; if (selected != null) selected (this, EventArgs.Empty); } }