【发布时间】:2016-09-03 12:54:27
【问题描述】:
我试图让条目在聚焦时选择所有文本。我有一个用于在 Android 上执行此操作的自定义渲染器,但希望它也可以在 Windows 8 上运行。如何在 Xamarin Forms 中为 Windows 创建自定义渲染?这是我所拥有的:
[程序集:ExportRenderer(typeof(Xamarin.Forms.Entry), typeof(DrivingLog.Windows.MyEntryRenderer))]
命名空间 DrivingLog.Windows{
公共类 MyEntryRenderer:EntryRenderer {
受保护的覆盖无效 OnElementChanged(ElementChangedEventArgs e) {
base.OnElementChanged(e);
if (e.OldElement == null) {
var nativeEditText = (global::Windows.UI.Xaml.Controls.TextBox)Control;
nativeEditText.ManipulationStarted += (object sender, ManipulationStartedRoutedEventArgs args) => {
nativeEditText.SelectAll();
};
}
}
}
}
【问题讨论】:
-
您目前所拥有的有什么问题吗?你有什么具体的问题?
-
@Jason 代码没有选择 TextBox 中的文本。我也尝试过更改 TextBox 的文本颜色,但它仍然不起作用。 xamarin 不使用渲染器。
标签: windows windows-runtime win-universal-app xamarin.forms custom-renderer