如何更改 Xamarin 表单中占位符的文本颜色

How to change the Text color of placeholder in Xamarin forms

是否可以更改部分占位符的文本颜色。

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

我想将星号“*”颜色更改为红色,其余文本将使用默认颜色。

感谢任何帮助!

您可以尝试以下解决方法:

EntryLabel 包装成 StackLayout。并使 StackLayout 像一个带占位符的条目。

代码是这样的:

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;
        }
    }
}

结果是: