Xamarin detects programmatically changing textbox

In Xamarin, I need to define a programmatic change to a textbox. .valueChanged()

only works when the end user changes the value. I need a way to call the method when the value changes with a method that I don't have access to. It looks like it's possible with an observer, but I can't seem to find any information on how to implement one for this.

+3


source to share


2 answers


I was luckily able to figure out how to do this. Let's say you have a UITextField "myTextField"

.

In the method, ViewDidLoad()

one could put myTextField.AddObserver ("text", NSKeyValueObservingOptions.New, ObserveValue);



The first parameter is the value you should be watching. The list of properties for UITextField

can be found here here . The last parameter is the method you want to call when a change is observed.

The method you are calling must use a parameter Foundation.NSObservedChange

, which is why my method signature was public void ObserveValue(Foundation.NSObservedChange a)

. Hope this helps someone else having similar problems.

+1


source


Nothing works for me except the delegate method textField:shouldChangeCharactersInRange:replacementString:

:

    [Export("textField:shouldChangeCharactersInRange:replacementString:")]
    public bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
    {
        return true;
    }

      



More on this bugzilla report .

0


source







All Articles