tags:

views:

97

answers:

1

How can I define a common Style for the TextBox and the PasswordBox?

My approach, I have define a Style for the TargetType FrameworkElement but this doesnt work as common style, then few propertys doesnt exist on the FrameworkElement.

My TextBox Style is equals the PasswordBoxStyle

<Style TargetType="{x:Type TextBox}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="MinHeight" Value="30"/>
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="FontFamily" Value="Verdana"/>
    <Setter Property="FontSize" Value="14"/>
    <Setter Property="Template">
     <Setter.Value>
      <ControlTemplate TargetType="{x:Type TextBox}">
       <Border Name="Border" CornerRadius="4" Padding="2" Background="White" BorderBrush="Black" BorderThickness="1" >
        <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
       </Border>
      </ControlTemplate>
     </Setter.Value>
    </Setter>
</Style>
+1  A: 

Try something like this

<Style x:Key="textboxPasswordboxStyles">
  <Setter Property="Control.ControlProperty" Value="value" />
  <Setter Property="TextBox.TextboxSpecproperty" Value="value" />
  <Setter Property="PasswordBox.PasswordBoxSpecProperty" Value="value" />
</Style>
<Style TargetType="{x:Type TextBox}"
    BasedOn="{StaticResource textboxPasswordboxStyles}">
</Style>
<Style TargetType="{x:Type PasswordBox}"
    BasedOn="{StaticResource textboxPasswordboxStyles}">
</Style>
ArsenMkrt
Style Property "PasswordBoxSpecProperty" doesnt found in "System.Windows.Controls.PasswordBox"same for "ControlProperty" "System.Windows.Controls.Control" and "TextboxSpecproperty" "System.Windows.Controls.TextBox"
Mario Priebe
ah lol, okay I understand.. i have solved ... TextBox.MinHeight thx : )
Mario Priebe