Google Xamarin.Forms Custom Renderer: Borderless Entry (C# - Xaml) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Tuesday, 18 February 2020

Xamarin.Forms Custom Renderer: Borderless Entry (C# - Xaml)

Introduction:
In this article, we can learn how to create entry without border using custom renderer

Description:
In Xamarin.Forms, there is no way to set border less properties to Entry in Xaml. Alternately we have to use custom renderers in platform specific projects like below

Let's create render class in Android project
  1. [assembly: ExportRenderer(typeof(Entry), typeof(BorderlessEntryRenderer))]    
  2. namespace FirstApp.Android.Renderers    
  3. {    
  4.     public class BorderlessEntryRenderer : EntryRenderer    
  5.     {    
  6.         protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)    
  7.         {    
  8.             base.OnElementChanged(e);    
  9.             if (e.OldElement == null)    
  10.             {    
  11.                 Control.Background = null;    
  12.             }    
  13.         }    
  14.     }    

Let's create render class in iOS project
  1. [assembly: ExportRenderer(typeof(Entry), typeof(BorderlessEntryRenderer))]  
  2. namespace FirstApp.iOS.Renderers  
  3. {  
  4.     public class BorderlessEntryRenderer : EntryRenderer  
  5.     {  
  6.         protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)  
  7.         {  
  8.             base.OnElementPropertyChanged(sender, e);  
  9.                
  10.             Control.Layer.BorderWidth = 0;  
  11.             Control.BorderStyle = UITextBorderStyle.None;  
  12.         }  
  13.     }  
  14. }  
FeedBack Note: Please share your thoughts, what you think about this post, Is this post really helpful for you? I always welcome if you drop comments on this post and it would be impressive.

Follow me always at @Subramanyam_B

No comments:

Post a Comment

Search Engine Submission - AddMe