0

我试图让条目在聚焦时选择所有文本。我有一个用于在 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();

                };

            }

        }

    }

}
4

1 回答 1

0

我发现了问题,渲染器类在 Main Page.xaml.cs 文件中。它需要位于没有与之关联的 xaml 的文件中,才能将程序集标记识别为 Xamarin Forms 2.0

于 2016-05-10T14:34:08.123 回答