2016-11-20 2 views
0

ich es verwenden, um die Ecken von TextBox abzurunden,WPF PasswordBox Abgerundete Ecken

<ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}"> 
     <Border Background="{TemplateBinding Background}" 
      x:Name="Bd" BorderBrush="#FFE6DDDD" 
      BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10"> 
      <ScrollViewer x:Name="PART_ContentHost"/> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/> 
       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
      </Trigger> 
      <Trigger Property="Width" Value="Auto"> 
       <Setter Property="MinWidth" Value="100"/> 
      </Trigger> 
      <Trigger Property="Height" Value="Auto"> 
       <Setter Property="MinHeight" Value="20"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 

Und ich anwenden,

 <TextBox Template="{StaticResource TextBoxBaseControlTemplate}" 
      Height="25" 
      Margin="168,100,139,194" 
      HorizontalContentAlignment="Center" 
      VerticalContentAlignment="Center" 
      Background="{x:Null}" 
      BorderBrush="{x:Null}" 
      FontFamily="Aller Light">    
     </TextBox> 

Mission abgeschlossen

enter image description here

Dann möchte ich tun in PasswordBox,

<ControlTemplate x:Key="passwordbox" TargetType="{x:Type PasswordBox}"> 
     <Border Background="{TemplateBinding Background}" 
      x:Name="Bd" BorderBrush="#FFE6DDDD" 
      BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10"> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/> 
       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
      </Trigger> 
      <Trigger Property="Width" Value="Auto"> 
       <Setter Property="MinWidth" Value="100"/> 
      </Trigger> 
      <Trigger Property="Height" Value="Auto"> 
       <Setter Property="MinHeight" Value="20"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 

gelten

<PasswordBox Template="{StaticResource passwordbox}" 
       Height="25" 
       Margin="168,140,139,154" 
       HorizontalContentAlignment="Center" 
       VerticalContentAlignment="Center" 
       Background="{x:Null}" 
       Password="someonepass"> 
    </PasswordBox> 

es scheint erfolgreich zu sein, aber der Inhalt nicht eingegeben werden kann. (Zweite Box)

enter image description here

wenn ich Vorlage löschen, ist in der Regel

enter image description here

Wie es zu beheben? Danke ...

+0

Sieht so aus, als hätten Sie ein 'PART_' vergessen. –

Antwort

0

Ihre PasswordBox Kontrollschablone verfehlt einen Teil mit dem Namen "PART_ContentHost" (typischerweise ein ScrollViewer). Nehmen Sie als Beispiel Ihre TextBoxBase Vorlage.

So sollte Ihr temaplate sein:

<ControlTemplate x:Key="passwordbox" TargetType="{x:Type PasswordBox}"> 
    <Border Background="{TemplateBinding Background}" 
     x:Name="Bd" BorderBrush="#FFE6DDDD" 
     BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10"> 
     <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> 
    </Border> 
    <ControlTemplate.Triggers> 
     <Trigger Property="IsEnabled" Value="False"> 
      <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/> 
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
     </Trigger> 
     <Trigger Property="Width" Value="Auto"> 
      <Setter Property="MinWidth" Value="100"/> 
     </Trigger> 
     <Trigger Property="Height" Value="Auto"> 
      <Setter Property="MinHeight" Value="20"/> 
     </Trigger> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 

Ich hoffe, dass es Ihnen helfen kann.