Xamarin формирует xaml-связывание в iOS, но работает в Android - PullRequest
0 голосов
/ 04 сентября 2018

Это работало до недавнего времени. Я попытался понизить XF безрезультатно. Он работает в Android, но не работает в iOS.

У меня есть пользовательский элемент управления, который отображает текстовую запись, и подкласс этого элемента управления, который отображает его многострочную версию. В iOS метка для одной строки отображается пустой, но работает многострочно.

Часть моей страницы:

<TableView HasUnevenRows="True" Intent="Form">
                <TableView.Root>
                    <TableSection Title="Details">
                        <view:TextEditor Label="Name" Text="{Binding Name}" />
                        <view:TextAreaEditor Label="Address" Text="{Binding Address}" />

И мой пользовательский элемент управления:

public class TextEditor : ViewCell
    {

        public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(TextEditor), null, defaultBindingMode: BindingMode.TwoWay);

        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        public static readonly BindableProperty LabelProperty = BindableProperty.Create("Label", typeof(string), typeof(TextEditor), null, defaultBindingMode: BindingMode.TwoWay);

        public string Label
        {
            get { return (string)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }

        protected TextEntry TextControl { get; set; }
        protected Editor AreaControl { get; set; }
        protected Label LabelControl { get; set; }

        public TextEditor() : this(false)
        {
        }
        public TextEditor(bool isMultiline)
        {
            var gridLayout = new Grid
            {
                Padding = 0,
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions = {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    }
                },
                ColumnDefinitions = {
                    new ColumnDefinition {
                        Width = new GridLength (1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength (2, GridUnitType.Star)
                    }
                }
            };

            LabelControl = new Label
            {
                Margin = 10,
                HorizontalTextAlignment = TextAlignment.Start,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.StartAndExpand,
                FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)),
                LineBreakMode = LineBreakMode.TailTruncation,
                TextColor = Palette.Caption
            };
            LabelControl.SetBinding(Xamarin.Forms.Label.TextProperty, new Binding("Label", BindingMode.TwoWay, source: this));
            gridLayout.Children.Add(LabelControl, 0, 0);


            if (isMultiline)
            {
                Height = 60;
                AreaControl = new Editor
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Margin = 0,
                    Keyboard = Keyboard.Text,
                    VerticalOptions = LayoutOptions.StartAndExpand,
                    //HeightRequest = 60,
                    AutoSize = EditorAutoSizeOption.TextChanges,
                };
                AreaControl.FontSize = Styles.GetEditorFontSize(AreaControl);

                AreaControl.SetBinding(Xamarin.Forms.Editor.TextProperty, new Binding("Text", BindingMode.TwoWay, source: this));
                gridLayout.Children.Add(AreaControl, 1, 0);
            }
            else
            {
                TextControl = new TextEntry
                {
                    //VerticalOptions = LayoutOptions.StartAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    HorizontalTextAlignment = TextAlignment.Start,
                    //HeightRequest = 30,
                    Margin = 0,
                    Keyboard = Keyboard.Text,
                };
                TextControl.FontSize = Styles.GetEditorFontSize(TextControl);

                TextControl.SetBinding(Entry.TextProperty, new Binding("Text", BindingMode.TwoWay, source: this));
                gridLayout.Children.Add(TextControl, 1, 0);
            }

            View = gridLayout;
            View.BindingContext = this;
        }
    }



    public class TextAreaEditor : TextEditor
    {
        public TextAreaEditor() : base(true)
        {
        }
    }
...