当聚焦时改变颜色

问题描述 投票:0回答:1

我想在聚焦文本框时改变颜色,但是我收到此错误:

'UIView.Focused'不能分配给它-只读

public UITextField text;
 UITextField.Focused += OnFocused 

    private void OnFocused(object sender, FocusEventArgs focusEventArgs) {

  }
c# ios xamarin xamarin.ios
1个回答
0
投票

您可以使用此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();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.