Как изменить цвет текста заполнителя в формах Xamarin - PullRequest
1 голос
/ 12 марта 2019

Можно ли изменить цвет текста части заполнителя.

<Controls:BorderlessEntry Grid.Row="1" Grid.Column="0" x:Name="ABS_ID" Placeholder="Enter Name Here *"/>

Я хочу поменять цвет звездочки "*" на красный, а остальной текст будет иметь цвет по умолчанию.

Любая помощь приветствуется!

1 Ответ

2 голосов
/ 13 марта 2019

Вы можете попробовать следующий обходной путь:

Оберните Entry и Label в StackLayout.И сделайте StackLayout как Entry с заполнителем.

Код выглядит так:

MainPage.xaml:

<StackLayout Orientation="Horizontal" HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand">
            <Entry  x:Name="ABS_ID" 
                    Text="Enter Name Here     "
                    HorizontalOptions="Start" 
                    Focused="OnEntryFocused" 
                    Unfocused="OnEntryUnFocused"/>
            <Label x:Name="ABS_ID2" 
                    Text="*" 
                    TextColor="Red" 
                    HorizontalOptions="StartAndExpand"  
                    VerticalTextAlignment="Center" 
                    Margin="-20"/>
        </StackLayout>

MainPage.xaml.cs:

public partial class MainPage : ContentPage
    {
        bool showPlaceHolder = true;
        public MainPage()
        {
            InitializeComponent();
        }
        void OnEntryFocused(object sender, EventArgs e)
        {
            if (showPlaceHolder) {
                ABS_ID.Text = "";
                ABS_ID2.Text = "";
            }
        }
        void OnEntryUnFocused(object sender, EventArgs e)
        {
            if ((ABS_ID.Text == "") && (ABS_ID2.Text == ""))
            {
                ABS_ID.Text = "Enter Name Here ";
                ABS_ID2.Text = "*";
                showPlaceHolder = true;
            }
            else {
                showPlaceHolder = false;
            }
        }

    }

И результат:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...