PasswordBox?

Dec 1, 2009 at 2:31 AM

Hi,

Any chance of getting the PasswordBox styled as well? I've tried to duplicate the TextBox style but the background of the PasswordBox remains white while the background of the TextBox is as per the style.

Thanks,
Corneliu 

Jun 24, 2011 at 11:40 AM
Edited Jun 24, 2011 at 1:13 PM

Yes, you actually can.

I did it with Dave's Glossy style, but I imagine it's the same with the others, mostly. Worked for me like a charm.

Change the textbox style

from

 <Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}" > ...
                <ControlTemplate TargetType="{x:Type TextBox}">...

to

 <Style x:Key="TextBoxDefault" TargetType="{x:Type Control}" > ...
                <ControlTemplate> ...

Then base your TextBox, PasswordBox, RichtTextBox styles upon that style:

    <!-- TextBox -->
    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBoxDefault}" />

    <!-- PasswordBox -->
    <Style TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource TextBoxDefault}">
        <Setter Property="PasswordChar" Value="●"/>
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    </Style>

    <!--RichTextBox -->
    <Style TargetType="{x:Type RichTextBox}" BasedOn="{StaticResource TextBoxDefault}">
        <Style.Resources>
            <Style TargetType="{x:Type Paragraph}">
                <Setter Property="Margin" Value="2"/>
            </Style>
        </Style.Resources>
    </Style>