Stumbled upon this bug https://github.com/xamarin/Xamarin.Forms/issues/10789 when trying to work with a centered entry.
Tried to solve it locally by doing a custom renderer but having some troubles along the way. This is what i currently have:
[assembly: Xamarin.Forms.ExportRenderer(typeof(Entry), typeof(CustomEntryRenderer))]
namespace Project.MacOS.Renderers
{
public class CustomEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
var element = e.NewElement as Entry;
if (Control != null && element != null)
{
Control.BackgroundColor = NSColor.Clear;
Control.Bordered = false;
var stringHeight = Control.AttributedStringValue.Size.Height;
var titleRect = Bounds;
var oldOriginY = this.Bounds.Y;
var res = titleRect.Y + (Bounds.Size.Height - stringHeight) / 2.0;
titleRect.Y = (System.nfloat)res;
var res2 = titleRect.Size.Height - (titleRect.Y - oldOriginY);
titleRect.Size.Height = res2;
}
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
}
}
}
So I followed this question: Set text vertical center in NSTextField
But having a few issues. First issue is that I am unable to set the titleRect.Size.Height = res2;
as it is complaining about "Cannot modify the return value of ´CGRECT.Size´ because it is not a variable. Second issue is how I assign these newly added values to the control itself so that i can test it and see if it worked.