Picker Xamarin中的左对齐图标从默认右侧形成macOS

问题描述

我正在尝试自定义Xamarin形式macOS的Picker,但没有成功。我创建了一个工作正常的渲染器,但是添加属性似乎并未对选择器进行任何更改。

目标是使图标左对齐,使文本在右侧。现在,该图标在右侧,文本在左侧。

public class CustomPickerRenderer : PickerRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
    {
        base.OnElementChanged(e);
        var element = e.NewElement as Picker;

        if (Control != null && element != null)
        {
            Control.Bordered = false;
            Control.Font = NSFont.FromFontName("Helvetica Neue",(System.nfloat)element.FontSize);
            Control.Bordered = false;
            Control.Alignment = NSTextAlignment.Right;

            Control.AttributedTitle = new NSAttributedString("",foregroundColor: element.TextColor.ToNSColor(),paragraphStyle: new NSMutableParagraphStyle()
            {
                Alignment = NSTextAlignment.Right,Linespacing = 0f,ParagraphSpacing = 0f,ParagraphSpacingBefore = 0f
            });

            Control.ImagePosition = NSCellImagePosition.ImageLeft;
            Control.Cell.ImagePosition = NSCellImagePosition.ImageLeft;

        }
    }

    protected override void OnElementPropertyChanged(object sender,System.ComponentModel.PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender,e);
        var element = (Picker)this.Element;

        if (e.PropertyName == Picker.ItemsSourceProperty.PropertyName ||
            e.PropertyName == Picker.TitleProperty.PropertyName)
        {
            Control.AddItems(element.Items.ToArray());
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)