2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
Step 1: Create a custom SfAutoComplete control. A custom SfAutoComplete control can be created by sub-classing the SfAutoComplete control as shown in the following codes. XAMLMainpage.Xaml <ContentPage.Content> <StackLayout Padding="50"> <local:CustomAutoComplete/> </StackLayout> </ContentPage.Content>
C#MainPage.Xaml.cs public class CustomAutoComplete : SfAutoComplete { }
The custom SfAutoComplete control is created in .NET Standard library project and is simply an SfAutoComplete control. Customization of the control will be carried out in the custom renderer, so no additional implementation is required in the custom SfAutoComplete control.
Step 2: Create a custom renderer in Android.
C#[assembly : ExportRenderer(typeof(CustomAutoComplete),typeof(AutoCompleteRenderer))] namespace Auto_Renderer.Droid { public class AutoCompleteRenderer : SfAutoCompleteRenderer { protected override void OnElementChanged(ElementChangedEventArgs<SfAutoComplete> e) { base.OnElementChanged(e); if (Control != null) { Control.GetAutoEditText().Gravity = GravityFlags.CenterHorizontal; } } } }
The call to the base class's OnElementChanged method instantiates an Android SfAutoComplete with a reference to assign the control to the renderer's Control property.
The Text Alignment is then set to center with the Control.GetAutoEditText().Gravity.
Step 3: Create a custom renderer in iOS.
C#[assembly: ExportRenderer(typeof(CustomAutoComplete), typeof(AutoCompleteRenderer))] namespace Auto_Renderer.iOS { public class AutoCompleteRenderer : SfAutoCompleteRenderer { protected override void OnElementChanged(ElementChangedEventArgs<SfAutoComplete> e) { base.OnElementChanged(e); if (Control != null) { Control.TextField.TextAlignment = UITextAlignment.Center; } } } }
The call to the base class's OnElementChanged method instantiates an iOS SfAutoComplete with a reference to assign the control to the renderer's Control property.
The Text Alignment is then set to center with the UITextAlignment.Center.
Step 4: Create a custom renderer in UWP.
C#[assembly: ExportRenderer(typeof(CustomAutoComplete), typeof(AutoCompleteRenderer))] namespace Auto_Renderer.UWP { public class AutoCompleteRenderer : SfAutoCompleteRenderer { protected override void OnElementChanged(ElementChangedEventArgs<SfAutoComplete> e) { base.OnElementChanged(e); if (Control != null) { Control.TextAlignment = Windows.UI.Xaml.TextAlignment.Center; } } } }
The call to the base class's OnElementChanged method instantiates a SfAutoComplete control with a reference to assign the control to the renderer's Control property.
The Text Alignment is then set to center with the Windows.UI.Xaml.TextAlignment.Center. You can download the entire source code of this demo. |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.