2009-10-08 93 views
0

嗯。 。 。我正在失去理智。 。 。還是我?錯誤或用戶錯誤?無法將TextBlock的VerticalAlignment屬性設置爲中心

我正在爲一些基本數據輸入創建一個WPF應用程序。我正在使用文本塊來標記文本框,但碰到了一個障礙。爲什麼我不能垂直居中文本塊?我無法改變垂直對齊。無論我在屬性上設置什麼值,文本塊都保留在頂部。我希望他們居中!我可以改變水平對齊沒問題。

下面包含了XAML文件的內容,包括樣式。

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      x:Class="SL3_ContactEntry.MainPage" 
      Width="500" 
      Background="#FF99DF52"> 

    <UserControl.Resources> 
     <Style x:Key="MyTextBlockStyle" 
       TargetType="TextBlock"> 
      <Setter Property="FontSize" 
        Value="12" /> 
      <Setter Property="Margin" 
        Value="2" /> 
      <Setter Property="Width" 
        Value="Auto" /> 
      <Setter Property="Height" 
        Value="28" /> 
      <Setter Property="HorizontalAlignment" 
        Value="Right" /> 
      <Setter Property="VerticalAlignment" 
        Value="Center" /> 
     </Style> 
     <Style x:Key="MyTextBoxStyle" 
       TargetType="TextBox"> 
      <Setter Property="FontSize" 
        Value="12" /> 
      <Setter Property="Margin" 
        Value="2" /> 
      <Setter Property="Width" 
        Value="Auto" /> 
      <Setter Property="Height" 
        Value="28" /> 
     </Style> 
     <Style x:Key="MyButtonStyle" 
       TargetType="Button"> 
      <Setter Property="FontSize" 
        Value="12" /> 
      <Setter Property="Margin" 
        Value="2" /> 
      <Setter Property="Width" 
        Value="100" /> 
      <Setter Property="Height" 
        Value="33" /> 
     </Style> 
    </UserControl.Resources> 

    <Grid ShowGridLines="True"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="0.81*" /> 
      <RowDefinition Height="0.19*" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <StackPanel Orientation="Vertical" 
        Grid.Column="0" 
        Margin="5"> 
      <TextBlock Name="FName" 
         Text="First Name" 
         Style="{StaticResource MyTextBlockStyle}" /> 
      <TextBlock Name="LName" 
         Text="Last Name" 
         Style="{StaticResource MyTextBlockStyle}" /> 
      <TextBlock Name="StreetAddress" 
         Text="Street Address" 
         Style="{StaticResource MyTextBlockStyle}" /> 
      <TextBlock Name="City" 
         Text="City" 
         Style="{StaticResource MyTextBlockStyle}" /> 
      <TextBlock Name="State" 
         Text="State" 
         Style="{StaticResource MyTextBlockStyle}" /> 
      <TextBlock Name="ZipCode" 
         Text="Zip Code" 
         Style="{StaticResource MyTextBlockStyle}" /> 
     </StackPanel> 
     <StackPanel Orientation="Vertical" 
        Grid.Column="1" 
        Margin="5"> 
      <TextBox Name="txtFName" 
        Style="{StaticResource MyTextBoxStyle}" /> 
      <TextBox Name="txtLName" 
        Style="{StaticResource MyTextBoxStyle}" /> 
      <TextBox Name="txtStreetAddress" 
        Style="{StaticResource MyTextBoxStyle}" /> 
      <TextBox Name="txtCity" 
        Style="{StaticResource MyTextBoxStyle}" /> 
      <TextBox Name="txtState" 
        Style="{StaticResource MyTextBoxStyle}" /> 
      <TextBox Name="txtZipCode" 
        Style="{StaticResource MyTextBoxStyle}" /> 
      <Button Content="OK" 
        Style="{StaticResource MyButtonStyle}" /> 
     </StackPanel> 
    </Grid> 
</UserControl> 

回答

0

我不是100%肯定它爲什麼不爲中心,大概有上的元素設置的高度來完成,但你可以做的是應用填充到的TextBlocks,讓他們與文本框爲中心。

相關問題