cas*_*las 2 c# xml mvvmcross xamarin
我想知道我怎么能在in中启用和禁用编辑功能.EditTextmvvmcross
<EditText
style="@style/InputNumbersEditText"
android:layout_weight="1"
android:layout_width="0dp"
android:focusable="true"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
local:MvxBind="Text Age" />
Run Code Online (Sandbox Code Playgroud)
由于android:editable="false"被弃用,你应该设置android:inputType="none"对禁止输入EditText.如果你正在寻找绑定inputType的EditText与MvvmCross,您可以创建一个值转换器这需要从您的视图模型的输入值,并返回类型回答Android.Text.InputTypes.
示例实现:
在您的Android项目中添加一个类,其中包含以下内容:
public class EditTextEnabledValueConverter : MvxValueConverter<bool, InputTypes>
{
protected override InputTypes Convert(bool value, Type targetType, object parameter, CultureInfo culture)
{
if (value)
return InputTypes.ClassNumber | InputTypes.NumberFlagDecimal | InputTypes.NumberFlagSigned;
return InputTypes.Null;
}
}
Run Code Online (Sandbox Code Playgroud)
并在您的布局文件中:
<EditText
style="@style/InputNumbersEditText"
android:layout_weight="1"
android:layout_width="0dp"
android:focusable="true"
android:layout_height="wrap_content"
local:MvxBind="Text Age; InputType EditTextEnabled(MyProperty)" />
Run Code Online (Sandbox Code Playgroud)
其中MyProperty是ViewModel上的可绑定布尔值.您可以使用任何类型作为源类型,它不必是布尔值.快乐转换!
| 归档时间: |
|
| 查看次数: |
994 次 |
| 最近记录: |