我在项目中拥有以下nextButton.addEventListener('click', this.switchMonth.bind(
this,
true, // next
undefined, // month
undefined, // year
undefined, // dayUTC
undefined, // dates
undefined // datesChosen
));
控件:
<div class="media" *ngFor="let p of phonebook">
<a class="list-group-item" (click)="onSelectedPhone(p)">
<h4 class=" media-heading list-group-item-heading"> {{p.name}} </h4>
<div class="row">
<div class="col-md-9">
<p class="list-group-item-text" [ngClass]="{'highlight':p.acive}">{{p.number}}</p>
</div>
</div>
</a>
</div>
以及以下自定义Android渲染器:
Xamarin.Forms
问题在于控件无法从渲染器接收文本(即public partial class AutoCompleteView : Xamarin.Forms.View
{
public event EventHandler<TextChangedEventArgs> TextChanged;
public static readonly BindableProperty TextProperty = BindableProperty.Create(
propertyName: "Text",
returnType: typeof(string),
declaringType: typeof(string),
defaultBindingMode: BindingMode.TwoWay);
public static readonly BindableProperty SuggestionsProperty = BindableProperty.Create(
propertyName: "Suggestions",
returnType: typeof(IEnumerable<string>),
declaringType: typeof(ObservableCollection<string>),
defaultBindingMode: BindingMode.OneWay);
public IEnumerable<string> Suggestions
{
get => (IEnumerable<string>)GetValue(SuggestionsProperty);
set => SetValue(SuggestionsProperty, value);
}
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public AutoCompleteView () : base()
{
InitializeComponent ();
}
private void OnTextChanged(TextChangedEventArgs e)
{
TextChanged?.Invoke(this, e);
}
}
设置器和绑定模型的设置器均未调用)。我该如何解决这个问题?
答案 0 :(得分:0)
谢谢mjwills,我在这里发现了一个逻辑错误。 this.Control.Text = autoComplete.Text
显然应该颠倒(即autoComplete.Text = this.Control.Text
),因为this.Control
是本机控件,应将文本更改传递给自定义AutoCompleteView
。