您可以通过创建具有 可绑定属性 的自定义 View(如 ForegroundTextColor)然后创建自定义渲染器来实现此目的。 p>
在自定义渲染器中,您可以从平台特定的渲染器继承,即在 WindowsPhone 上它是:-
Xamarin.Forms.Platform.WinPhone.SearchBarRenderer
然后您可以监视您创建的 bindable-property 的属性更改并设置使用的 平台原生控件 Text-color更改 SearchBar 的非编辑视图的外观。
您还必须至少监视 IsFocused 并在 WindowsPhone 上应用颜色。这也可能适用于其他平台。
更新 1:-
========
在回复您的评论时,您不必自己呈现整个 SearchBar。
如果您从 renderer 继承,您可以更好地自定义内容。
具体参考 Android 来实现这一点,你必须参考 AutoCompleteTextView 然后你可以调用 SetTextColor 来改变颜色。
更新 2:-
==========
SearchBar 是 Android 中的复合控件。
AutoCompleteTextView 在层次结构中埋藏得相当深。
在 4.4 上,可以使用以下代码找到。其他版本可能会有所不同。然而,这绝不是使用序数索引进行生产的好方法:-
AutoCompleteTextView objAutoTextView = (AutoCompleteTextView)(((this.Control.GetChildAt(0) as ViewGroup).GetChildAt(2) as ViewGroup).GetChildAt(1) as ViewGroup).GetChildAt(0);
this 是 renderer 类。
然后可以用颜色调用objAutoTextView.SetTextColor,实现SearchBar前景文本的颜色变化。