我正在使用 Syncfusion 及其控件 SfMaskedEdit,我在绑定(bind)到我的 viewModel 中的属性时遇到问题;我试过这样的事情:
<StackLayout BindingContext="{Binding PagePrueba}">
<syncfusion:SfMaskedEdit x:Name="maskedEdit"
Keyboard="Telephone"
MaskType="RegEx"
Mask="+1(\d{3})\d{7}"
ValueChanged="MaskedEdit_OnValueChanged"/>
但它不起作用。它给我一个错误 MaskedEdit_OnValueChanged not fund。即使在我的 viewModel 中我有
private void MaskedEdit_OnValueChanged(object sender, Syncfusion.XForms.MaskedEdit.ValueChangedEventArgs e)
如果我用一个普通的条目来做这件事
<Entry Text="{Binding TelephoneNumber}"></Entry>
它完美地工作。这是控件的文档: Syncfusion
谢谢大家的宝贵时间
最佳答案
我已经检查了您使用 SfMaskedEdit 在 View 模型中绑定(bind)属性的查询。为此,您可以将 SfMaskedEdit 控件的 Value 属性与 View 模型属性绑定(bind)。
在 ViewModel 类中:
class MaskedEditViewModel
{
private string valueText;
public string ValueText
{
get
{
return valueText;
}
set
{
SetValue(value);
}
}
private void SetValue(string data)
{
valueText = data;
Application.Current.MainPage.DisplayAlert("Alert", string.Format("The current value is {0}", data),"OK");
}
}
XAML
<syncfusion:SfMaskedEdit Mask="00/00/0000" ValidationMode="KeyPress"
x:Name="maskedEdit" Value="{Binding ValueText}">
您可以从下面找到示例 http://www.syncfusion.com/downloads/support/directtrac/general/ze/MaskedEdit_MVVM938250655
关于c# - 如何在 xamarin 中从 Syncfusion 绑定(bind) SfMaskedEdit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50880210/