How can I get the selected item of my custom picker? It always goes back to the initial state "Sonstige" (= "Other"). So the value is not changeable.
I'm facing the problem for hours but have no further idea on how to fix it. I'm new to custom rendering.
I would like to use the DoneBtn_Clicked
function to set the new value to the picker:
void DoneBtn_Clicked(object sender, EventArgs e){}
Screenshot of the custom picker:
My code: Class PickerRendererIos.cs :
[assembly: ExportRenderer(typeof(MyPickerRenderer), typeof(PickerRendererIos))]
namespace DigitalNatives.iOS
{
public class PickerRendererIos : PickerRenderer, IUIPickerViewDelegate
{
IElementController ElementController => Element as IElementController;
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
UIPickerView pickerView = (UIPickerView)Control.InputView;
pickerView.WeakDelegate = this;
pickerView.BackgroundColor = UIColor.White; //set the background color of pickerview
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
Control.Layer.BorderWidth = 1;
Control.BorderStyle = UITextBorderStyle.Line;
Control.TextColor = UIColor.Blue;
}
[Export("pickerView:viewForRow:forComponent:reusingView:")]
public UIView GetView(UIPickerView pickerView, nint row, nint component, UIView view)
{
UILabel label = new UILabel
{
TextColor = UIColor.Blue,
Text = Element.Items[(int)row].ToString(),
TextAlignment = UITextAlignment.Center,
};
var picker = this.Element;
return label;
}
}
}