Xamarin UWP设置PasswordBox占位符颜色

时间:2017-08-21 10:02:30

标签: xamarin uwp passwordbox

我有一个带登录页面的Xamarin.Forms共享项目。对于UWP,我想使用密码显示功能,这就是我需要PasswordBox控件的原因。我想在UWP中为PasswordBox控件设置placeholdertext颜色。问题是Xamarin没有PasswordBoxRenderer,而且PasswordBox控件没有编辑占位符前景色的属性。

我无法找到更新的/ Xamarin解决方案。任何帮助或解决方案都表示赞赏。

1 个答案:

答案 0 :(得分:0)

在PasswordBox资源中覆盖默认画笔的最佳方法,如下所示:

<PasswordBox PlaceholderText="PASSWORD">
            <PasswordBox.Resources>
                <SolidColorBrush x:Key="TextControlPlaceholderForegroundFocused" Color="Red"/>
                <SolidColorBrush x:Key="TextControlPlaceholderForeground" Color="Red"/>
            </PasswordBox.Resources>
        </PasswordBox>

您也可以覆盖:TextControlPlaceholderForegroundPointerOver,TextControlPlaceholderForegroundDisabled

将新的UserControl添加到您的项目,然后将其更改为:

<PasswordBox
    x:Class="App3.CustomPasswordBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Width="200" Height="50" PlaceholderText="PlaceHolder">
    <PasswordBox.Resources>
        <SolidColorBrush x:Key="TextControlPlaceholderForegroundFocused" Color="Red"/>
        <SolidColorBrush x:Key="TextControlPlaceholderForeground" Color="Red"/>
    </PasswordBox.Resources>
</PasswordBox>

删除CustomPasswordBox.xaml.cs。

创建新的渲染器:

public class PasswordRenderer : ViewRenderer<Entry, CustomPasswordBox>
    {
        
    }