我想在聚焦文本框时改变颜色,但是我收到此错误:
'UIView.Focused'不能分配给它-只读
public UITextField text;
UITextField.Focused += OnFocused
private void OnFocused(object sender, FocusEventArgs focusEventArgs) {
}
您可以使用此AttachProperty
:
public static class Attach
{
public static DependencyProperty IsFocusedProperty = DependencyProperty.RegisterAttached("IsFocused", typeof(bool), typeof(Attach), new UIPropertyMetadata(false, OnIsFocusedChanged));
public static bool GetIsFocused(DependencyObject dependencyObject)
{
return (bool)dependencyObject.GetValue(IsFocusedProperty);
}
public static void SetIsFocused(DependencyObject dependencyObject, bool value)
{
dependencyObject.SetValue(IsFocusedProperty, value);
}
public static void OnIsFocusedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var textField = dependencyObject as UITextField;
textField.Focus();
}
}