xamarin.forms - 如何更改 Xamarin 表单中占位符的文本颜色
问题描述
是否可以更改部分占位符的文本颜色。
<Controls:BorderlessEntry Grid.Row="1" Grid.Column="0"
x:Name="ABS_ID"
Placeholder="Enter Name Here *"/>
我想将星号“*”颜色更改为红色,其余文本将具有默认颜色。
任何帮助表示赞赏!
解决方案
您可以尝试以下解决方法:
Entry
将 a和 a包装Label
成 a 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;
}
}
}
结果是:
推荐阅读
- typescript - 具有自动递增 id 列的 oneToMany 关系的 TypeORM Cascade 插入因非空约束而失败
- excel - SUMIF:公式作为标准不适用于整列
- php - 带斜线的 PHP 日期转换
- javascript - Formik & Yup:如何验证提供的日期是否为十八岁?
- spring - 未知的生命周期阶段“.qualitygate.wait=true”
- excel - 找到第一个“To Date”,选择“To Date”下的单元格,将值粘贴到前面的单元格中,然后转到下一个 To Date
- python - 在列表中查找并删除文本
- reactjs - 有没有办法在 WordPress Gutenberg 编辑器中添加新标签
- visual-studio - Visual Studio 2019 应用建议快捷方式
- nlp - DialogFlow 上的 Botium K-fold 交叉验证引发前置条件错误