我一直在寻找有关如何执行此操作的信息:
我需要创建一些RootElement
s,具体取决于RadioGroup的值,我不太确定如何或在何处编写它。
理想情况下,它会创建一个新的RootElement
(ColorsRoot)并将其称为“Color1”,“Color2”等。
这是我到目前为止所得到的。
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
int i = 1;
RootElement ColumnRoot;
RootElement ColorsRoot = new RootElement ("Color" + i, new RadioGroup ("color" + i, 0)){
new Section(){
new RadioElement("Red", "color"+i),
new RadioElement("Light red", "color"+i),
new RadioElement("Dark red", "color"+i),
new RadioElement("Green", "color"+i),
new RadioElement("Light green", "color"+i),
new RadioElement("Dark green", "color"+i),
new RadioElement("Blue", "color"+i),
new RadioElement("Light blue", "color"+i),
new RadioElement("Dark blue", "color"+i),
}
};
EntryElement NameEntry;
BooleanElement OrientationBool;
var rootView = new RootElement("TouchBow"){
new Section(){
new RootElement("New rainbow"){
new Section("New rainbow"){
(NameEntry = new EntryElement("Name", "Enter a name", "")),
(ColumnRoot = new RootElement("Columns", new RadioGroup("columns",1)){
new Section(){
new RadioElement("3", "columns"),
new RadioElement("5", "columns"),
new RadioElement("9", "columns")
}
}),
//MAGIC COLOR IS HAPPENING RIGHT HERE?!
new RootElement("Colors"){
new Section(){
(ColorsRoot),
(ColorsRoot)
}
},
(OrientationBool = new BooleanElement("Horizontal", false)),
},
new Section(){
new StringElement("Save rainbow", delegate{
Console.WriteLine ("Name.Value: "
+ NameEntry.Value +
". ColumnRoot.RadioSelected: "
+ ColumnRoot.RadioSelected +
". Color: "
+ ColorsRoot.RadioSelected +
". Orientation: "
+ OrientationBool.Value);
}),
new StringElement("View rainbow",
() => { new UIAlertView("Tapped", "String Element Tapped", null, "ok", null).Show();
})
}
},
new StringElement("Load rainbow", delegate{
Console.WriteLine ("Name.Value: " + NameEntry.Value + ". ColumnRoot.RadioSelected: " + ColumnRoot.RadioSelected);
})
}
};
// If you have defined a view, add it here:
// window.AddSubview (navigationController.View);
var dvc = new DialogViewController(rootView);
var nav = new UINavigationController(dvc);
window.RootViewController = nav;
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
答案 0 :(得分:1)
请记住,您可以保存对层次结构各个部分的引用,并且可以动态添加和删除元素。