2017-10-24 7 views
-1

こんにちは、私はそれを定義したグリッドを塗りつぶしにしたいTextBoxを持っています。それを行うために、私はそれをフィットさせることができるように伸ばす。問題は、テキストが中央ではなく上に書き込まれることです。整列を中心にすると、TextBoxはもう伸縮しません。TextBox全体のテキストがストレッチモードのときに中央に揃えるテキストボックスのコンテンツ

<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0" Text="Wall Temperature [C]"/> 
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="3" Grid.Column="1" Text="150.0"/> 
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="4" Grid.Column="0" Text="Wall Temperature [C]"/> 
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="4" Grid.Column="1" Text="150.5"/> 

それはこの

enter image description here

答えて

1

のようになります。あなたはそれでテキストを垂直に配向されるようにする場合TextBoxControlTemplateを変更する必要があります

<Grid> 
    <Grid.Resources> 
     <SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/> 
     <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/> 
     <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/> 
     <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type TextBox}"> 
         <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           Background="{TemplateBinding Background}" 
           SnapsToDevicePixels="True"> 
          <ScrollViewer x:Name="PART_ContentHost" Focusable="false" 
             HorizontalScrollBarVisibility="Hidden" 
             VerticalScrollBarVisibility="Hidden" 
             VerticalAlignment="Center"/> 
         </Border> 
         <ControlTemplate.Triggers> 
          <Trigger Property="IsEnabled" Value="false"> 
           <Setter Property="Opacity" TargetName="border" Value="0.56"/> 
          </Trigger> 
          <Trigger Property="IsMouseOver" Value="true"> 
           <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/> 
          </Trigger> 
          <Trigger Property="IsKeyboardFocused" Value="true"> 
           <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Grid.Resources> 
    ... 
    <TextBox Height="100" Text="Centered text..." /> 
</Grid> 

enter image description here

+0

パーフェクト、ありがとうあまりにも。 – VegaBrothers

関連する問題