Darkwood
Darkwood

Reputation: 111

How can I add new Monotouch dialog views dynamically?

When creating views in Monotouch Dialog, one possible way is to create .cs files which hold the view information like so:

[Caption("Create user")]
[Alignment(UITextAlignment.Center)]
public RegistrationSchema CreateAccount;

But say I needed to have button added dynamically, like so:

//This is what I'd like to do, but there doesn't seem to be any support for this
_newUserSection = new Section("Create user) {
    new RegistrationSchema()
};

Any ideas?

Edit My RegistrationSchema.cs file

public class RegistrationSchema
{
    [Section("Fill out the form")]

    [Caption("E-mail")]
    [Entry(KeyboardType=UIKeyboardType.EmailAddress)]
    public string Email;

    //more stuff here
}

Upvotes: 2

Views: 940

Answers (1)

Krumelur
Krumelur

Reputation: 33058

// Create a new section
var section = new Section("A section");
// Create a new element
var elem = new StringElement("String Element")
// Add element to section
section.Add(elem);
// Add section to root.
Root.Add(section);
// Refresh
Root.ReloadData();

All well documented here https://github.com/migueldeicaza/MonoTouch.Dialog and in the Xamarin tutorials, like there http://blog.xamarin.com/2012/02/10/easily-create-ios-user-interfaces-with-monotouch-dialog/

To push a new controller, use a RootElement:

var newRoot = RootElement("Another root", new ThisWillBePushedController());
root.Add(newRoot);

Tapping the newRoot will push the ThisWillBePushedController(). Note that you'll have to override MonoTouch.DialogViewController and call the base c'tor passing TRUE for the last argument "pushing" if you're using a UINavigationController.

Upvotes: 3

Related Questions