2

I have been searching high and low for information on how to do this:

I need to create a number of RootElements depending on the value of a RadioGroup, I am not quite sure how or where to write it.

Ideally it would create a new RootElement (ColorsRoot) and call it "Color1", "Color2" etc.

Here's what I've got so far.

    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;
    }
poupou
  • 43,413
  • 6
  • 77
  • 174
mackwerk
  • 1,689
  • 4
  • 21
  • 44

1 Answers1

1

Remember that you can save references to the various parts of your hierarchy and you can add and remove elements dynamically.

miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76
  • How would I go about adding the `RootElement`s in question here? It's going to be triggered by the value of the `RadioGroup` `ColumnRoot` ? – mackwerk Oct 13 '12 at 15:52
  • Kind bump, can you perhaps show a code example of doing this, miguel.de.icaza? – mackwerk Oct 24 '12 at 18:43