MAUI iOS — проблема HideSoftInputOnTapped не работаетC#

Место общения программистов C#
Anonymous
MAUI iOS — проблема HideSoftInputOnTapped не работает

Сообщение Anonymous »

У меня есть проект MAUI .NET 8, и я столкнулся с проблемой: когда я щелкаю за пределами настраиваемой записи, когда она находится в фокусе, она не теряет фокус и не скрывает программную клавиатуру, даже когда я устанавливаю HideSoftInputOnTapped= «Верно».
Однако эта проблема не возникнет, если CustomRender не реализован.
Пожалуйста, помогите мне решить эту проблему.
Найдите код











public class CustomEntry : Entry
{
public new event EventHandler Completed;

public CustomEntry()
{
// Default parameter
}

public CustomEntry(string PropertyID)
{
ClassId = PropertyID;
BackgroundColor = Colors.Transparent;
HorizontalOptions = LayoutOptions.FillAndExpand;
}

public const string ReturnKeyPropertyName = "ReturnKeyType";

public static readonly BindableProperty ReturnKeyTypeProperty = BindableProperty.Create(
propertyName: ReturnKeyPropertyName,
returnType: typeof(ReturnKeyTypes),
declaringType: typeof(CustomEntry),
defaultValue: ReturnKeyTypes.Done);

public ReturnKeyTypes ReturnKeyType
{
get { return (ReturnKeyTypes)GetValue(ReturnKeyTypeProperty); }
set { SetValue(ReturnKeyTypeProperty, value); }
}

public Constants.eKeyboardTypes KeyBoardType
{
get;
set;
}

public void InvokeCompleted()
{
if (this.Completed != null)
this.Completed.Invoke(this, null);
}

public void SetVisible()
{
Enable();
IsVisible = true;
}

public void Enable()
{
IsEnabled = true;
BackgroundColor = Colors.Transparent;
}

public void ReadOnly()
{
SetVisible();
IsEnabled = false;
BackgroundColor = Constants.ReadOnlyBackGroundColor;
}

public void Disabled()
{
SetVisible();
IsEnabled = false;
BackgroundColor = Constants.DisabledBackGroundColor;
}

}

public enum ReturnKeyTypes : int
{
Default,
Go,
Google,
Join,
Next,
Route,
Search,
Send,
Yahoo,
Done,
EmergencyCall,
Continue
}

public class CustomEntry_IOS: EntryRenderer
{
public CustomEntry_IOS()
{
}

protected override void OnElementChanged(ElementChangedEventArgs e)
{
CustomEntry entry = (CustomEntry)this.Element;
base.OnElementChanged(e);
if ((Control != null) && (e.NewElement != null))
Control.ReturnKeyType = (e.NewElement as CustomEntry).ReturnKeyType.GetValueFromDescription();
Control.Placeholder = entry.Placeholder;
//Control?.ResignFirstResponder();
// Editor Action is called when the return button is pressed

//if (entry != null && entry.Keyboard == Keyboard.Numeric)
//{
// Control.KeyboardType = UIKeyboardType.NumbersAndPunctuation;
//}
if (Control != null)
Control.ShouldReturn += (UITextField tf) =>
{
entry.InvokeCompleted();
return true;
};
if (entry != null)
{
SetKeybordType(entry.KeyBoardType);
}
}

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
try
{
base.OnElementPropertyChanged(sender, e);
// Control?.ResignFirstResponder();
if (e.PropertyName == CustomEntry.ReturnKeyPropertyName)
{

Control.ReturnKeyType = (sender as CustomEntry).ReturnKeyType.GetValueFromDescription();

//Control.ReturnKeyType = UIReturnKeyType.Continue;
}
if ((sender as CustomEntry) != null && (sender as CustomEntry).Keyboard == Keyboard.Numeric)
{
Control.KeyboardType = UIKeyboardType.PhonePad;
}
}
catch (Exception ex)
{
// AppDelegate.log?.WriteLog(ex, Location: this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name);
}

}

void SetKeybordType(Constants.eKeyboardTypes keyboardType)
{
switch (keyboardType)
{
case Constants.eKeyboardTypes.Default:
this.Control.KeyboardType = UIKeyboardType.Default;
break;
case Constants.eKeyboardTypes.Email:
this.Control.KeyboardType = UIKeyboardType.EmailAddress;
break;
case Constants.eKeyboardTypes.Numeric:
this.Control.KeyboardType = UIKeyboardType.NumberPad;
break;
case Constants.eKeyboardTypes.NumericWithDecimal:
this.Control.KeyboardType = UIKeyboardType.DecimalPad;
break;
case Constants.eKeyboardTypes.NumericWithMinusAndDigit:
case Constants.eKeyboardTypes.NumericWithMinus:
this.Control.KeyboardType = UIKeyboardType.NumbersAndPunctuation;
break;
default:
this.Control.KeyboardType = UIKeyboardType.Default;
break;
}
}
}

public static class EnumExtensions
{
public static UIReturnKeyType GetValueFromDescription(this ReturnKeyTypes value)
{
var type = typeof(UIReturnKeyType);
if (!type.IsEnum) throw new InvalidOperationException();
foreach (var field in type.GetFields())
{
var attribute = Attribute.GetCustomAttribute(field,
typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attribute != null)
{
if (attribute.Description == value.ToString())
return (UIReturnKeyType)field.GetValue(null);
}
else
{
if (field.Name == value.ToString())
return (UIReturnKeyType)field.GetValue(null);
}
}
throw new NotSupportedException($"Not supported on iOS: {value}");
}
}


Подробнее здесь: https://stackoverflow.com/questions/790 ... king-issue

Вернуться в «C#»