Search code examples
windowswindows-runtimewin-universal-appxamarin.formscustom-renderer

Xamarin Forms WinRT Entry Custom Renderer


I am trying to have make the Entry select all text when it is focused. I have a custom renderer for doing so on Android, but would like it to work on Windows 8 as well. How can I create a custom render for Windows in Xamarin Forms? Here is what I have:

[assembly: ExportRenderer(typeof(Xamarin.Forms.Entry), typeof(DrivingLog.Windows.MyEntryRenderer))]
namespace DrivingLog.Windows{

    public class MyEntryRenderer : EntryRenderer {

        protected override void 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();

                };

            }

        }

    }

}

Solution

  • I found the issue, the renderer class was in the Main Page.xaml.cs file. It needed to be in a file that did not have xaml associated with it for the assembly tag to be recognized be Xamarin Forms 2.0