Home > OS >  How to set an Italic Placeholder to an Entry in Xamarin
How to set an Italic Placeholder to an Entry in Xamarin

Time:06-13

Hi guys I've been looking into a solution to set the placeholder of an entry to italic.

CodePudding user response:

I have an unusual solution to get the effect you want.

At first, set the FontAttributes as Italic in the xaml, such as:

<Entry x:Name="test" FontAttributes="Italic" Placeholder="Placeholder" TextChanged="test_TextChanged"/>

And then, change the FontAttributes to None in the TextChanged Event, such as:

private void test_TextChanged(object sender, TextChangedEventArgs e)
    {
        Entry entry = sender as Entry;
        if(entry.Text.Length > 0)
        {
            entry.FontAttributes = FontAttributes.None;
        }
        else
        {
            entry.FontAttributes = FontAttributes.Italic;
        }
    }
  • Related