2011-12-06 7 views
0

Windows PhoneのPasswordBoxにパスワードを中央揃えすることができません。中央揃えが無効になります。テキストを中心に揃える方法はありますか?は、WP7のパスワードボックスにパスワードの中央揃えができません。

verticalcontentalignmentとhorizo​​ntalcontentalignmentを中央に設定しようとしましたが効果がありません。または、パスワードボックスの境界とパスワードの間にスペースを置くことができます。

Alfah

答えて

3

あなたは、その効果を達成するためにコントロールテンプレートを編集することができます。

<phone:PhoneApplicationPage 
    x:Class="PhoneApp3.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignWidth="480" 
    d:DesignHeight="768" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" 
    Orientation="Portrait" 
    shell:SystemTray.IsVisible="True"> 
    <phone:PhoneApplicationPage.Resources> 
     <ControlTemplate 
      x:Key="PhoneDisabledPasswordBoxTemplate" 
      TargetType="PasswordBox"> 
      <Border 
       x:Name="ContentElement" 
       BorderThickness="0" 
       Margin="{StaticResource PhonePasswordBoxInnerMargin}" 
       Padding="{TemplateBinding Padding}" /> 
     </ControlTemplate> 
     <Style 
      x:Key="PasswordBoxStyle1" 
      TargetType="PasswordBox"> 
      <Setter 
       Property="FontFamily" 
       Value="{StaticResource PhoneFontFamilyNormal}" /> 
      <Setter 
       Property="FontSize" 
       Value="{StaticResource PhoneFontSizeMediumLarge}" /> 
      <Setter 
       Property="Background" 
       Value="{StaticResource PhoneTextBoxBrush}" /> 
      <Setter 
       Property="Foreground" 
       Value="{StaticResource PhoneTextBoxForegroundBrush}" /> 
      <Setter 
       Property="BorderBrush" 
       Value="{StaticResource PhoneTextBoxBrush}" /> 
      <Setter 
       Property="BorderThickness" 
       Value="{StaticResource PhoneBorderThickness}" /> 
      <Setter 
       Property="SelectionBackground" 
       Value="{StaticResource PhoneAccentBrush}" /> 
      <Setter 
       Property="SelectionForeground" 
       Value="{StaticResource PhoneContrastBackgroundBrush}" /> 
      <Setter 
       Property="Padding" 
       Value="2" /> 
      <Setter 
       Property="Template"> 
       <Setter.Value> 
        <ControlTemplate 
         TargetType="PasswordBox"> 
         <Grid 
          Background="Transparent"> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup 
            x:Name="CommonStates"> 
            <VisualState 
             x:Name="Normal" /> 
            <VisualState 
             x:Name="MouseOver" /> 
            <VisualState 
             x:Name="Disabled"> 
             <Storyboard> 
              <ObjectAnimationUsingKeyFrames 
               Storyboard.TargetProperty="Visibility" 
               Storyboard.TargetName="EnabledBorder"> 
               <DiscreteObjectKeyFrame 
                KeyTime="0"> 
                <DiscreteObjectKeyFrame.Value> 
                 <Visibility>Collapsed</Visibility> 
                </DiscreteObjectKeyFrame.Value> 
               </DiscreteObjectKeyFrame> 
              </ObjectAnimationUsingKeyFrames> 
              <ObjectAnimationUsingKeyFrames 
               Storyboard.TargetProperty="Visibility" 
               Storyboard.TargetName="DisabledBorder"> 
               <DiscreteObjectKeyFrame 
                KeyTime="0"> 
                <DiscreteObjectKeyFrame.Value> 
                 <Visibility>Visible</Visibility> 
                </DiscreteObjectKeyFrame.Value> 
               </DiscreteObjectKeyFrame> 
              </ObjectAnimationUsingKeyFrames> 
             </Storyboard> 
            </VisualState> 
           </VisualStateGroup> 
           <VisualStateGroup 
            x:Name="FocusStates"> 
            <VisualState 
             x:Name="Focused"> 
             <Storyboard> 
              <ObjectAnimationUsingKeyFrames 
               Storyboard.TargetProperty="Background" 
               Storyboard.TargetName="EnabledBorder"> 
               <DiscreteObjectKeyFrame 
                KeyTime="0" 
                Value="{StaticResource PhoneTextBoxEditBackgroundBrush}" /> 
              </ObjectAnimationUsingKeyFrames> 
              <ObjectAnimationUsingKeyFrames 
               Storyboard.TargetProperty="BorderBrush" 
               Storyboard.TargetName="EnabledBorder"> 
               <DiscreteObjectKeyFrame 
                KeyTime="0" 
                Value="{StaticResource PhoneTextBoxEditBorderBrush}" /> 
              </ObjectAnimationUsingKeyFrames> 
             </Storyboard> 
            </VisualState> 
            <VisualState 
             x:Name="Unfocused" /> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
          <Border 
           x:Name="EnabledBorder" 
           BorderBrush="{TemplateBinding BorderBrush}" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           Background="{TemplateBinding Background}" 
           Margin="{StaticResource PhoneTouchTargetOverhang}"> 
           <Border 
            x:Name="ContentElement" 
            HorizontalAlignment="Center" 
            BorderThickness="0" 
            Margin="{StaticResource PhonePasswordBoxInnerMargin}" 
            Padding="{TemplateBinding Padding}" /> 
          </Border> 
          <Border 
           x:Name="DisabledBorder" 
           BorderBrush="{StaticResource PhoneDisabledBrush}" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           Background="Transparent" 
           Margin="{StaticResource PhoneTouchTargetOverhang}" 
           Visibility="Collapsed"> 
           <PasswordBox 
            x:Name="DisabledContent" 
            HorizontalAlignment="Center" 
            Background="Transparent" 
            Foreground="{StaticResource PhoneDisabledBrush}" 
            Password="{TemplateBinding Password}" 
            PasswordChar="{TemplateBinding PasswordChar}" 
            Template="{StaticResource PhoneDisabledPasswordBoxTemplate}" /> 
          </Border> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </phone:PhoneApplicationPage.Resources> 

    <!--LayoutRoot is the root grid where all page content is placed--> 
    <Grid 
     x:Name="LayoutRoot" 
     Background="Transparent"> 
     <Grid.RowDefinitions> 
      <RowDefinition 
       Height="Auto" /> 
      <RowDefinition 
       Height="*" /> 
     </Grid.RowDefinitions> 

     <!--TitlePanel contains the name of the application and page title--> 
     <StackPanel 
      x:Name="TitlePanel" 
      Grid.Row="0" 
      Margin="12,17,0,28"> 
      <TextBlock 
       x:Name="ApplicationTitle" 
       Text="MY APPLICATION" 
       Style="{StaticResource PhoneTextNormalStyle}" /> 
      <TextBlock 
       x:Name="PageTitle" 
       Text="page name" 
       Margin="9,-7,0,0" 
       Style="{StaticResource PhoneTextTitle1Style}" /> 
     </StackPanel> 

     <!--ContentPanel - place additional content here--> 
     <Grid 
      x:Name="ContentPanel" 
      Grid.Row="1" 
      Margin="12,0,12,0"> 
      <PasswordBox 
       VerticalAlignment="Center" 
       Style="{StaticResource PasswordBoxStyle1}" /> 
     </Grid> 
    </Grid> 
</phone:PhoneApplicationPage> 
+0

は私のために働いていない... WP 8.0/8.1用 –

関連する問題