Question

Does anyone have a code sample or any advice on how I can implement the ShouldChangeCharacters event on the monotouch EntryElement class?

Presumably I need to inherit EntryElement and implement a UITextField (which has the ShouldChangeCharacters event).....but I don't have much experience in exposing events when inheriting classes etc.

It seems that I should be doing the following, but how do I expose this ShouldChangeCharacters event?

using MonoTouch.Dialog;
using MonoTouch.UIKit;

class MyEntryElement : EntryElement 
{

    protected override UITextField CreateTextField(RectangleF frame)
    {
        var field = base.CreateTextField(frame);

        //How do I expose this?
        //field.ShouldChangeCharacters

        return field;
    }

}

Essentially I want to be able to type:

MyEntryElement test = new MyEntryElement ();
        test.ShouldChangeCharacters += etc....
Was it helpful?

Solution

You almost have it, just make field a class-level variable, and make a public property for it. You could also just make a property for an event, and give that to the field, but I think that is slightly more complicated.

class MyEntryElement : EntryElement 
{
    UITextField field; // Class-level variable
    protected override UITextField CreateTextField(RectangleF frame)
    {
        field = base.CreateTextField(frame);

        //How do I expose this?
        //field.ShouldChangeCharacters

        return field;
    }

    public UITextField Field {
        get { return field; }
    }

}

Now you can do this:

MyEntryElement test = new MyEntryElement ();
test.Field.ShouldChangeCharacters += etc....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top