7

While creating a WPF application which includes a PasswordBox control, I tried to set the PasswordChar to display '<' instead of '*'. I wrote the following code:

<PasswordBox PasswordChar="<"></PasswordBox>

When using this code, the following error is reported:

Error 1 The value "<" is not valid in an attribute.

1
  • I might have up-voted this question if you had showed the error message that you were receiving.
    – user700390
    Commented Jun 29, 2015 at 11:43

4 Answers 4

10

Use this instead:

<PasswordBox PasswordChar="&lt;"></PasswordBox>

You'll find a comprehensive list of symbols and how to write them in XAML in this MSDN article: XML Character Entities and XAML

4

< is a special character in XML. You need to use &lt;, as in:

<PasswordBox PasswordChar="&lt;" />

or set it in code.

XAML

<PasswordBox x:Name="tbPassword" />

Code

tbPassword.PasswordChar = '<';
2

'<' is a reserved character, try using this instead:

<PasswordBox PasswordChar="&lt;"></PasswordBox>
2

You will have to use &lt; for < and &gt; for > in xaml:

 <PasswordBox PasswordChar="&lt;"></PasswordBox> 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.