2016-11-20 45 views
0

私はWPF PasswordBox角丸

<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> 

、テキストボックスの角を丸めるためにそれを使用して、私が適用されます、

 <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> 

ミッションはその後、私はしたい

enter image description here

を完了しましたパスワードボックスで行う、

<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> 

は、成功のようです

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

適用されますが、コンテンツを入力することはできません。 (2番目のボックス)

enter image description here

私はテンプレートを削除した場合、それを修正するためにどのように正常に

enter image description here

のですか?ありがとう...

+0

あなたは 'PART_'を忘れてしまったようです。 –

答えて

0

PasswordBoxコントロールテンプレートは、「PART_ContentHost」という名前の部分(基本的にScrollViewer)を見逃しています。あなたのTextBoxBaseテンプレートをサンプルとして受け取ります。

だからあなたtemaplateは次のようになります。

<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> 

私はそれはあなたを助けることができると思います。