2017-12-29 50 views
0

内のテキスト、私はキャンバスにテキストを中央にしようと、私は何を私は現在、ここにやっていることは、この方法を、把握することはできません例えばS6の場合はS66に設定すれば、6を加えてその位置を保持します...キャンバス内のテキストを常に中央に置いておきたいと思います。キャンバスのアラインメントおよびSOキャンバス

また、キャンバスはStackPanelにあります。スタックパネルの右側にあるようにしたいと思いますが、そこには行かないので、どうすれば修正できますか?

result

しかし、それはすべての画面に適応し、静的ではなくなるように:

<Page 
    x:Class="Rittensport_Software.CalculatePage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Rittensport_Software" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="#E6E6E6"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="1*"></RowDefinition> 
      <RowDefinition Height="7*"></RowDefinition> 
     </Grid.RowDefinitions> 

     <!--Navigation bar--> 
     <Canvas Grid.Row="0" Background="#073D48" Opacity="0.8"></Canvas> 
     <!--Navigation--> 
     <StackPanel Orientation="Horizontal"> 
      <Image x:Name="mgBackBtn" Source="Assets/Icons/Back.png" Width="96" Height="96" /> 
      <TextBlock Text="REKENBLAD" Foreground="#F8F8F8" FontSize="35" VerticalAlignment="Center" /> 
      <TextBlock Text="(Deel 2)" Foreground="#F8F8F8" FontSize="35" VerticalAlignment="Center" Margin="30,0" /> 
     </StackPanel> 

     <!--There we will put the main shit in (also a grid because it is difficult) --> 
     <Grid Grid.Row="1"> 
      <Grid.RowDefinitions> 
       <RowDefinition></RowDefinition> 
       <RowDefinition></RowDefinition> 
       <RowDefinition></RowDefinition> 
      </Grid.RowDefinitions> 

      <!--Top items--> 
      <Grid Grid.Row="0"> 
       <Grid.RowDefinitions> 
        <RowDefinition></RowDefinition> 
        <RowDefinition></RowDefinition> 
       </Grid.RowDefinitions> 

       <StackPanel Grid.Row="0" Orientation="Horizontal"> 
        <StackPanel Orientation="Horizontal" Margin="140,41,0,0" VerticalAlignment="Top"> 
         <TextBlock Text="Klasse" FontFamily="Verdana" FontSize="35" /> 
         <ComboBox x:Name="ClassSelector" VerticalAlignment="Center" Margin="26,0"/> 

         <TextBlock Text="Nummer" FontFamily="Verdana" FontSize="35" /> 
         <ComboBox x:Name="StartNumbers" VerticalAlignment="Center" Margin="26,0"/> 

         <TextBlock Text="Deel" FontFamily="Verdana" FontSize="35" /> 
         <ComboBox x:Name="InputSegment" VerticalAlignment="Center" Margin="26,0"/> 
        </StackPanel> 
        <!--The current numer selected--> 
        <Canvas Background="#730D11" Width="138" Height="138" HorizontalAlignment="Right" VerticalAlignment="Center"> 
         <TextBlock Text="S6" Foreground="#EAEAEA" FontSize="50" VerticalAlignment="Center" HorizontalAlignment="Center" Canvas.Left="45" Canvas.Top="34" /> 
        </Canvas> 
       </StackPanel> 


       <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="140,0"> 
        <TextBlock Text="Piloot:" FontWeight="Bold" FontSize="35" /> 
        <TextBlock Text="NAAM Voornaam" FontSize="35" Margin="10,0" /> 
        <TextBlock Text="(tel)" FontSize="25" Margin="5,9" /> 

        <TextBlock Text="Navigator:" FontWeight="Bold" FontSize="35" Margin="306,0,0,0" /> 
        <TextBlock Text="NAAM Voornaam" FontSize="35" Margin="10,0" /> 
        <TextBlock Text="(tel)" FontSize="25" Margin="5,9" /> 
       </StackPanel> 

      </Grid> 

      <Grid Grid.Row="1"> 
       <Border BorderBrush="#707070" BorderThickness="0 1 0 0" Margin="70.5,0" /> 
       <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0,60,0,0"> 
        <TextBlock Text="Gemiste controles" Height="42" VerticalAlignment="Center" Foreground="#0F0F0F" FontSize="35" Margin="140,0,0,0" /> 
        <TextBox PlaceholderText="100" Height="42" VerticalAlignment="Center" /> 
       </StackPanel> 



</Grid> 

     <Grid Grid.Row="2"> 
      <Border BorderBrush="#707070" BorderThickness="0 1 0 0" Margin="70.5,0" /> 
     </Grid> 

    </Grid> 

</Grid> 

私が達成したい結果は以下の通りです:ここでは、私が現在使用してコードがあります...

答えて

0

私は常にキャンバスのテキストを中央に置いておきたいです

CanvasCanvas.LeftCanvas.Topプロパティを使用して、子要素の絶対位置のために意味されます。子のプロパティHorizontalAlignmentVerticalAlignmentの値はレイアウトに影響しません。センター利用Grid代わりCanvasの中にテキストを配置するには、次の

<Grid Background="#730D11" Width="138" Height="138"> 
    <TextBlock Text="S6" Foreground="#EAEAEA" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
</Grid> 

canvastはStackPanelのであり、私はそれがそのスタックパネルの右側になりたいが、それはそこに行くしないこと

StackPanelは、すべての子要素に合わせて必要なだけ大きくなります。子どものプロパティがLeftまたはRightに設定されている場合、その中に空白がないため、子どもの相違はありません。コンテンツを右揃えにするには、GridまたはRelativePanelを使用します。

+0

それはトリックでした!ありがとうございます!!!! – Robin

+0

@Robinよろしくお願いします! –