【问题标题】:Binding XAML to custom entry in xamarin.form.behavior将 XAML 绑定到 xamarin.form.behavior 中的自定义条目
【发布时间】:2015-08-10 03:12:49
【问题描述】:
【问题讨论】:
标签:
c#
xaml
xamarin
xamarin.forms
behavior
【解决方案1】:
首先声明你自定义的入口类:
public class YourCustomEntry : Entry
{
public YourCustomEntry()
{
}
public string YourCustomField { get; set; }
// You could also create a BindableProperty: http://xamandor.me/2015/02/27/custom-controls-with-xamarin-forms/
}
然后创建自定义行为:
public class NumericValidationBehavior : Behavior<YourCustomEntry>
{
protected override void OnAttachedTo(YourCustomEntry entry)
{
entry.TextChanged += OnEntryTextChanged;
base.OnAttachedTo(entry);
}
protected override void OnDetachingFrom(YourCustomEntry entry)
{
entry.TextChanged -= OnEntryTextChanged;
base.OnDetachingFrom(entry);
}
void OnEntryTextChanged(object sender, TextChangedEventArgs args)
{
// Do something with you custom property
((YourCustomEntry)sender).YourCustomField = "test";
}
}