Android.Widget.AutoCompleteTextView
是Android的一個View
。
解決方案PCL:
不能使用在Xamarin形式(PCL)ContentPage
具體View's
平臺。
要使用特定平臺View
,您應該使用custom render。 @JamesMontemagno有blog post顯示如何做你所需要的。
此代碼是草稿例請按此使用。
1 - 創建將在Android中被呈示爲AutoCompleteTextView
自己的定製Xamarin.Forms控制:
public class AutoCompleteView : View
{
// Place need properties here.
}
2 - 在Android項目添加渲染AutoCompleteView
:
[assembly: ExportRenderer(typeof(AutoCompleteView), typeof(AutoCompleteViewRenderer))]
namespace App.Droid
{
public class AutoCompleteViewRenderer : ViewRenderer<AutoCompleteView, AutoCompleteTextView>
{
// Initialize the AutoCompleteTextView
protected override void OnElementChanged (ElementChangedEventArgs<AutoComplete> e)
{
base.OnElementChanged (e);
if (e.OldElement != null || this.Element == null)
return;
var autoComplete = new AutoCompleteTextView(Forms.Context);
SetNativeControl (autoComplete);
}
// Use the control here.
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) {
base.OnElementPropertyChanged (sender, e);
if (this.Element == null || this.Control == null)
return;
// variable this.Control is the AutoCompleteTextView, so you an manipulate it.
}
}
}
共享項目解決方案:
當使用共享項目存在使用Native Embedding,像一個可能性:
...
var textView = new TextView (Forms.Context) { Text = originalText };
stackLayout.Children.Add (textView);
contentView.Content = textView.ToView();
...
能否請您給了一步做或添加一些代碼..thanks –
感謝jzeferion ..如果你自定義的familare渲染,你可以請爲你的答案添加代碼包含步驟.. –
我已經添加了一個簡單的例子來解釋如何渲染工作。欲瞭解更多詳情,請閱讀完整的博客文章。 – jzeferino