示例#1
0
        private View NameEntryView()
        {
            var lblTitle = new Label()
            {
                FontSize  = Sizes.TextMicro,
                Text      = AppText.profile_name_header,
                TextColor = Colors.TextFaded,
            };

            var entry = new Entry()
            {
                HorizontalOptions   = LayoutOptions.Fill,
                VerticalOptions     = LayoutOptions.Center,
                TextColor           = Colors.TextSpecial,
                FontAttributes      = FontAttributes.Bold,
                BackgroundColor     = Color.Transparent,
                FontSize            = Sizes.Title,
                Keyboard            = Keyboard.Text,
                IsSpellCheckEnabled = false,
            };

            entry.SetBinding(Entry.TextProperty, nameof(ViewModel.Name));
            entry.AddTouch((sender, args) =>
            {
                entry.Focus();
            });

            var pen = new SvgCachedImage()
            {
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.Center,
                HeightRequest     = Sizes.Title,
                WidthRequest      = Sizes.Title,
                Aspect            = Aspect.AspectFit,
                Source            = Images.ProfilePen,
            };

            pen.AddTouch((sender, args) =>
            {
                entry.Focus();
            });

            entry.Focused += (sender, args) =>
            {
                pen.IsVisible          = false;
                entry.InputTransparent = false;

                // crude fix to place cursor at end of text
                var text = entry.Text;
                entry.Text = "";
                entry.Text = text;
            };
            entry.Unfocused += (sender, args) =>
            {
                pen.IsVisible          = true;
                entry.InputTransparent = true;
            };

            return(new StackLayout()
            {
                Spacing = Device.RuntimePlatform == Device.Android ? -5 : 0,
                Children =
                {
                    lblTitle,
                    new Grid()
                    {
                        ColumnDefinitions = new ColumnDefinitionCollection()
                        {
                            new ColumnDefinition()
                            {
                                Width = GridLength.Star
                            },
                            new ColumnDefinition()
                            {
                                Width = GridLength.Auto
                            },
                        },
                        Children =
                        {
                            { entry,   0, 0 },
                            { pen,     1, 0 },
                        }
                    },
                }
            });
        }