2009-05-28 12 views
4

単純な入力フォームを作成しようとしているWPFフォームがあります。 2つのラベル、2つのテキストボックス、および「送信」ボタン。私はかなり良いレイアウトを持っている、私が得ることができない唯一のものは自分の "ラベル"が自分のセル内で右に揃えられることです。 TextAlign = "Right"とHorizo​​ntialAlign = "Right"の両方を試してみました。テキストをすべて移動させ、テキストボックスをオーバーレイします。セル内を移動するだけではありません。以下は、ウィンドウのXAMLです。WPFグリッドアイテムと右揃えテキスト

<Window x:Class="MyWebKeepAliveDesktop.Login" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MyWebKeepAlive Desktop - Login" WindowStyle="None" AllowsTransparency="true" Height="200" Width="400" > 

    <Border Background="#50FFFFFF" CornerRadius="7" BorderBrush="{StaticResource WindowFrameBrush}" BorderThickness="2,0,2,2"> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="30" /> 
       <RowDefinition/> 
      </Grid.RowDefinitions> 
      <Border Background="{StaticResource WindowFrameBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
       CornerRadius="5,5,0,0" Margin="-1,0,-1,0" MouseLeftButtonDown="DragWindow"> 
       <Grid> 
        <TextBlock Foreground="White" FontWeight="Bold" VerticalAlignment="Center" Margin="10,2,10,2" 
          Text="MyWebKeepAlive Desktop Login"/> 
        <Button Content="X" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" FontSize="7" 
        Width="15" Height="15" Padding="0" Command="ApplicationCommands.Close"/> 
       </Grid> 
      </Border> 
      <Grid Grid.Row="1" Width="350" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center"> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="35" /> 
        <RowDefinition Height="25" /> 
        <RowDefinition Height="25" /> 
        <RowDefinition Height="10" /> 
        <RowDefinition Height="30" /> 
       </Grid.RowDefinitions> 
       <TextBlock TextAlignment="center" Text="Please provide your username/password that is used on the MyWebKeepAlive.com site to login." TextWrapping="Wrap" Grid.Row="0" Grid.ColumnSpan="2" /> 
       <TextBlock Text="Username" FontWeight="Bold" Grid.Row="1" Grid.Column="0"/> 
       <TextBox Name="txtUsername" Width="150" Grid.Row="1" Grid.Column="1" /> 
       <TextBlock Text="Password" FontWeight="Bold" Grid.Row="2" /> 
       <TextBox Name="txtPassword" Width="150" Grid.Row="2" /> 
       <Button Name="btnLogin" Grid.Row="4" Grid.ColumnSpan="2"> 
        <TextBlock Text="Login" /> 
       </Button> 
      </Grid>    
     </Grid> 
    </Border> 
</Window> 
+1

追加:ShowGridLines = Trueのこれはあなたの行と列の制限 – vidalsasoon

答えて

11

グリッドには1つの列しか書かれていません。テキストボックスのGrid.Column = 1の設定をサポートするには2つ必要です。したがって、<ColumnDefinitions>ブロックを追加する必要があります。 XAMLを使用すると、WPFは両方のコントロールを同じ列に投げるだけで、表示される動作が変わります。

+0

おかげでピーターを閲覧役立つはず! Intellisenseは "ColumnDefinitions"を表示しないことで私を混乱させました。私はそれが必要だったものの、何かが欠けていると思った!すべてが良いです! –

2

これは私が思いついたものです。 WPFを自分で学習するだけです。 PeterAllenWebbが記載されているため、主な問題はColumnDefinitionsが不足していることです。私もTextAlignment="Right"属性を2つのTextBlocksに追加しました。あなたのグリッドタグに

<Grid Grid.Row="1" Width="350" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="35" /> 
       <RowDefinition Height="25" /> 
       <RowDefinition Height="25" /> 
       <RowDefinition Height="10" /> 
       <RowDefinition Height="30"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <TextBlock TextAlignment="center" Text="Please provide your username/password that is used on the MyWebKeepAlive.com site to login." TextWrapping="Wrap" Grid.Row="0" Grid.ColumnSpan="2" /> 
      <TextBlock Text="Username" TextAlignment="Right" FontWeight="Bold" Grid.Row="1" Grid.Column="0"/> 
      <TextBox Name="txtUsername" Width="150" Grid.Row="1" Grid.Column="1" /> 
      <TextBlock Text="Password" TextAlignment="Right" FontWeight="Bold" Grid.Row="2" /> 
      <TextBox Name="txtPassword" Width="150" Grid.Row="2" Grid.Column="1"/> 
      <Button Name="btnLogin" Grid.Row="4" Grid.ColumnSpan="2"> 
       <TextBlock Text="Login" /> 
      </Button> 
     </Grid> 
関連する問題