Forum Xamarin.Mac

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

NSTextField: Why does my NSNumberFormatter not work anymore when I add a method to EditingEnded?

GT4485GT4485 Member ✭✭

Look at the following example:
`using AppKit;
using CoreGraphics;
using Foundation;
using System;

namespace NSTextFieldValidation
{
public partial class ViewController : NSViewController
{
NSTextField Tbx1, Tbx2;
public ViewController(IntPtr handle) : base(handle)
{
}

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var fm = new NSNumberFormatter { Maximum = 999, Minimum = 0 };
        Tbx1 = new NSTextField(new CGRect(10, 50, 100, 30));
        View.AddSubview(Tbx1);
        Tbx1.PlaceholderString = "Tbx1";
        Tbx1.Formatter = fm;
        //Tbx1.EditingEnded += Tbx1_EditingEnded;

        Tbx2 = new NSTextField(new CGRect(150, 50, 100, 30));
        View.AddSubview(Tbx2);
        Tbx2.PlaceholderString = "Tbx2";
        Tbx2.Formatter = fm;
        Tbx2.EditingEnded += Tbx2_EditingEnded;
    }

    private void Tbx1_EditingEnded(object sender, EventArgs e)
    { Console.WriteLine("Tbx1"); }

    private void Tbx2_EditingEnded(object sender, EventArgs e)
    { Console.WriteLine("Tbx2"); }
}

}
`
Enter a digit in each textfield and exit the field with TAB or the mouse: no problem.
Enter a letter in each textfield: you cannot exit Tbx1 (that's OK), but you can exit Tbx2!

Why?

Best Answer

Answers

  • GT4485GT4485 Member ✭✭

    Hi LandLu.
    Thanks for your answer and your solution. It works well.
    Was my first solution a mistake? Or is there a bug in Xamarin (or Cocoa)?

  • LandLuLandLu Member, Xamarin Team Xamurai

    It seems something went wrong when we convert the delegate to events.
    You could raise an issue here:
    https://github.com/xamarin/xamarin-macios/issues

Sign In or Register to comment.