MahApps.Metro icon indicating copy to clipboard operation
MahApps.Metro copied to clipboard

PasswordBox shows no TextBoxHelper.ClearTextButton

Open arnoldpa opened this issue 11 years ago • 1 comments

Hey,

the PasswordBox shows no ClearTextButton if TextBoxHelper.ClearTextButton is true. TextBox shows it.

image

Version: MahApps.Metro.1.0.1-ALPHA007 .net4.5

Thanks for help.

arnoldpa avatar Dec 23 '14 16:12 arnoldpa

tl;dr: Wrong code in PasswordBox template.

Noticed this a few minutes ago and came here if anyone else had the same problem. This problem is also in MetroDemo, as the second PasswordBox should have a Clear button. I looked at the source of the default MahApps.Metro template for the PasswordBox and noticed this line:

Template="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonTemplate), Mode=OneWay}"

In the default TextBox style, the equivalent line is this one:

Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"

There is no line in the PasswordBox file that sets its Visibility property (which also means there is no line that sets it to Collapsed or something; how strange) in the default style, but that should be the case. In the Button version style for the TextBox, there is no visibility property, just a template property. So the PasswordBox's default style is probably using some code from the Button PasswordBox style.

I (or someone else) might be able to correct this issue, the TextBox and PasswordBox styling files should be nearly identical (except for some features the other does not have). Right now, they are not. I copied the Visibility line from TextBox's style and inserted it at the Template line (which I removed) of PasswordBox's style, and the Clear button appeared again.

It might also be useful to somehow 'merge' the default style and the button style, since the only differences between the TextBox styles is the Visibility/Template line difference (could be solved) and the additional triggers in the default style for controlling the opacity of the watermark text. The ButtonContent is set in both styles.

Any MahApps.Metro authors who have some new insights in the above information?

Dotnetifier avatar Dec 23 '14 20:12 Dotnetifier