Search code examples
xamarinxamarin.formsxamarin.androidxamarin.ios

Using Materialpickerrender once pick and cancel button Title shows top in Xamarin forms


enter image description hereWe are using visual material picker control in our app. If I select anything from the picker popup title shows the top and selected value below. If I click cancel from the picker popup title also shows top. It should be in the default state. How to resolve this xamarin forms android and ios?

internal class CustomMaterialPickerRenderer : MaterialPickerRenderer {

}

enter image description here


Solution

  • If I understand correctly , do you want to make the title back to the default position when clicking on the cancel button ?

    I test both on iOS and Android , the problem only occurs on Android side .

    The solution for Android platform :
    [assembly: ExportRenderer(typeof(Picker), typeof(MyRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]
    namespace FormsApp.Droid
    {
        class MyRenderer : MaterialPickerRenderer
        {
            Context _context;
    
            public MyRenderer(Context context) : base(context)
            {
                _context = context;        
            }
    
            protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                base.OnElementPropertyChanged(sender, e);
    
    
                if(Element.IsFocused == false)
                {
                    Control.EditText.ClearFocus();
                }
            }     
        }
    }