【问题标题】:Xamarin Forms WinRT Entry Custom RendererXamarin Forms WinRT 条目自定义渲染器
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-29
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多