2014-09-03 79 views
0

我使用下面的密码框代码它显示显示密码复选框,这是我whant。密码框IsPasswordRevealButtonEnabled显示自定义样式的复选框

<PasswordBox x:Uid="Password" Password="{Binding Password, Mode=TwoWay}" IsPasswordRevealButtonEnabled="True"> </PasswordBox> 

现在,作为一个要求,我需要在passwordbox FOUCS使用不同的颜色,所以我必须更新密码框的默认模板。我得到了here的默认模板。并更新了焦点视觉状态以改变背景颜色。现在,而不是密码显示复选框一个按钮显示在passsowrd框内(一旦按下它也会消失)。

我想显示密码显示复选框,而不是框中的按钮。我怎样才能做到这一点?有什么建议么?

回答

2

似乎确实MSDN上提供的模板与Windows Phone上的默认模板不匹配。但是你可以使用Blend轻松地提取它。

这里是确切的模板,你可以修改,以满足您的需求:

<x:Double x:Key="TextControlThemeMinWidth">51</x:Double> 
    <x:Double x:Key="TextControlThemeMinHeight">33</x:Double> 
    <Thickness x:Key="TextControlBorderThemeThickness">2.5001</Thickness> 
    <FontFamily x:Key="PhoneFontFamilyNormal">Segoe WP</FontFamily> 
    <x:Double x:Key="ContentControlFontSize">20.26</x:Double> 
    <Thickness x:Key="TextControlThemePadding">7,2.5,8,4</Thickness> 
    <Thickness x:Key="TextControlMarginThemeThickness">0,9.5,0,9.5</Thickness> 
    <Thickness x:Key="TextControlHeaderMarginThemeThickness">0,0,0,4.8</Thickness> 
    <Thickness x:Key="RichEditBoxTextThemeMargin">2.5,2.5,2.5,2.5</Thickness> 
    <Thickness x:Key="PasswordBoxCheckBoxThemeMargin">0,-6.5,0,0</Thickness> 
    <SolidColorBrush x:Key="TextBoxDisabledBackgroundThemeBrush" Color="Transparent"/> 
    <x:Double x:Key="TextControlBackgroundThemeOpacity">0.8</x:Double> 
    <x:Double x:Key="TextControlBorderThemeOpacity">0.8</x:Double> 
    <Style x:Key="PasswordBoxStyle" TargetType="PasswordBox"> 
     <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}"/> 
     <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}"/> 
     <Setter Property="SelectionHighlightColor" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}"/> 
     <Setter Property="Foreground" Value="{ThemeResource TextBoxForegroundThemeBrush}"/> 
     <Setter Property="Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/> 
     <Setter Property="BorderBrush" Value="{ThemeResource TextBoxBorderThemeBrush}"/> 
     <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}"/> 
     <Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}"/> 
     <Setter Property="FontSize" Value="{ThemeResource ContentControlFontSize}"/> 
     <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto"/> 
     <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto"/> 
     <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/> 
     <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/> 
     <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/> 
     <Setter Property="Margin" Value="{ThemeResource TextControlMarginThemeThickness}"/> 
     <Setter Property="VerticalAlignment" Value="Top"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="PasswordBox"> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="*"/> 
          <RowDefinition Height="Auto"/> 
         </Grid.RowDefinitions> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledHeaderForegroundThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Normal"> 
            <Storyboard> 
             <DoubleAnimation Duration="0" To="{ThemeResource TextControlBackgroundThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement"/> 
             <DoubleAnimation Duration="0" To="{ThemeResource TextControlBorderThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="PointerOver"/> 
           <VisualState x:Name="Focused"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PlaceholderTextContentPresenter"/> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxFocusedBackgroundThemeBrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="ButtonStates"> 
           <VisualState x:Name="ButtonVisible"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="RevealButton"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsChecked" Storyboard.TargetName="RevealButton"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="False"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="ButtonCollapsed"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="RevealButton"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsChecked" Storyboard.TargetName="RevealButton"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="False"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" Margin="{TemplateBinding BorderThickness}" Grid.Row="1"/> 
         <Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.Row="1"/> 
         <ContentPresenter x:Name="HeaderContentPresenter" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Margin="{ThemeResource TextControlHeaderMarginThemeThickness}" Grid.Row="0" Style="{StaticResource HeaderContentPresenterStyle}"/> 
         <ScrollViewer x:Name="ContentElement" AutomationProperties.AccessibilityView="Raw" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsTabStop="False" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" Margin="{ThemeResource RichEditBoxTextThemeMargin}" MinHeight="{ThemeResource TextControlThemeMinHeight}" Padding="{TemplateBinding Padding}" Grid.Row="1" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled"/> 
         <ContentControl x:Name="PlaceholderTextContentPresenter" Content="{TemplateBinding PlaceholderText}" Foreground="{ThemeResource TextBoxPlaceholderTextThemeBrush}" IsTabStop="False" Margin="{ThemeResource RichEditBoxTextThemeMargin}" Padding="{TemplateBinding Padding}" Grid.Row="1"/> 
         <CheckBox x:Name="RevealButton" Foreground="{ThemeResource TextBoxForegroundHeaderThemeBrush}" HorizontalAlignment="Left" IsTabStop="False" Margin="{ThemeResource PasswordBoxCheckBoxThemeMargin}" Grid.Row="2" Visibility="Collapsed" VerticalAlignment="Top"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
+0

的复选框,如果我设置的=器isChecked比真密码箱alwasy可见....我怎样才能解决,在样式...? – 2014-09-04 13:26:51

+0

任何含义! – 2014-09-04 13:47:42