Я пытаюсь привязать свойство PlainText
(, которое является свойством TwoWay Bindable, которое я создал в своем CustomEditor ) CustomEditor
, к переменной KeyString
при iOS
, исвяжите свойство Text
с KeyString
при Android
.
Я знаю, что привязка PlainText
к KeyString
при iOS
работает правильно (я проверял это), но привязка Text
к KeyString
для Android
завершается с System.ArgumentNullException
Value cannot be null. Parameter name: binding
Также IntelliSense подчеркивает части моего кода, которые используют BindingBase
в x:TypeAgruments
. Для первой части Intellisense говорит: PlainText does not support values of type OnPlatform(BindingBase)
, но код все еще работает, когда я запускаю его на моем iOS
эмуляторе. Это дает мне ошибку Text does not support values of type OnPlatform(BindingBase)
для Android
обязательной части кода, и это часть моего XAML, которую он не может запустить.
Ниже приведен мой код XAML
, любая идея, что яможет быть не так?
<Frame Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BorderColor="Black" Margin="0" Padding="0">
<controls:CustomEditor HeightRequest="80" IsPassword="True">
<controls:CustomEditor.PlainText>
<OnPlatform x:TypeArguments="BindingBase">
<On Platform="iOS" Value="{Binding KeyString}"/>
</OnPlatform>
</controls:CustomEditor.PlainText>
<controls:CustomEditor.Text>
<OnPlatform x:TypeArguments="BindingBase">
<On Platform="Android" Value="{Binding KeyString}"/>
</OnPlatform>
</controls:CustomEditor.Text>
<controls:CustomEditor.Effects>
<controls:PasswordEffect>
</controls:PasswordEffect>
</controls:CustomEditor.Effects>
</controls:CustomEditor>
</Frame>
В моем классе редактора у меня есть этот код:
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace MyApp.CustomControls
{
public class CustomEditor : Editor
{
public static readonly BindableProperty IsPasswordProperty =
BindableProperty.Create(nameof(IsPassword), typeof(bool), typeof(CustomEditor), false);
public static readonly BindableProperty PlainTextProperty =
BindableProperty.Create(nameof(PlainText),
typeof(string),
typeof(CustomEditor),
String.Empty,
defaultBindingMode:BindingMode.TwoWay,
propertyChanged:OnPlainTextChanged);
public bool IsPassword
{
get { return (bool)GetValue(IsPasswordProperty); }
set { SetValue(IsPasswordProperty, value); }
}
public string PlainText {
get { return (string)GetValue(PlainTextProperty); }
set { SetValue(PlainTextProperty, value); }
}
private static void OnPlainTextChanged(BindableObject bindable, object oldValue, object newValue)
{
var control = (CustomEditor)bindable;
if (newValue != null)
{
control.PlainText = newValue.ToString();
}
}
}
}