mackwerk
mackwerk

Reputation: 1687

Showing a number of RootElement(s) depending on the value of RadioElement with MonoTouch.Dialog

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;
    }

Upvotes: 2

Views: 272

Answers (1)

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

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

Upvotes: 1

Related Questions