2017-05-28 5 views
0

こんにちは、Main_Page.xamlにいくつかのボタンを追加しました。アプリケーションを実行しているときにウィンドウのサイズが変更されてしまいました。私は彼らがアプリケーションを実行するときに同じ割合を維持します。ボタンをページでサイズ変更する必要がありません.WPF

ボタン名は次のとおりです。Exercise_tab_left_button、Exercise_tab_right_button

<Page x:Class="TrackFit_Project.Main_Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:TrackFit_Project" 
    mc:Ignorable="d" 
    d:DesignHeight="453.635" d:DesignWidth="855.207" 
    Title="Main_Page" 
    ShowsNavigationUI = "false" > 

<TabControl Margin="10,10,10.333,10.333"> 
    <TabItem Header="Exercise" 
      HorizontalAlignment="Left" 
      Width="58" 
      Height="22" 
      Margin="-2,-2,0,0" 
      VerticalAlignment="Top"> 
     <Grid Background="#FFE5E5E5"> 
      <Button x:Name="Exercise_Tab_Profile_Button" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Click="profileButtonClick"> 
       <Image> 
        <Image.Source>stock profile image.png</Image.Source> 
       </Image> 
      </Button> 
      <Rectangle x:Name="Exercise_tab_rectangle" Fill="#FFCFC6C6" HorizontalAlignment="Left" Height="295" Margin="137,50,0,0" Stroke="Black" VerticalAlignment="Top" Width="625"/> 
      <TextBlock HorizontalAlignment="Left" Height="234" Margin="169,87,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="548"/> 
      **<Button x:Name="Exercise_tab_left_button" Content="&lt;" Margin="148,189,655,154" FontSize="18" FontWeight="Bold"/> 
      <Button x:Name="Exercise_tab_Right_button" Content="&gt;" Margin="717,189,83,155" FontSize="18" FontWeight="Bold"/>** 
      <TextBlock x:Name="Log_Out_Text_Block" HorizontalAlignment="Left" Margin="10,105,0,0" TextWrapping="Wrap" VerticalAlignment="Top" FontWeight="Bold"> 
        <Hyperlink x:Name="Log_out_hyperlink" Click="Log_out_hyperlink_Click">Log out</Hyperlink> 
      </TextBlock> 
     </Grid> 
</TabControl> 

This is what i want it to look likeThis is what i end up getting when i run the app

答えて

1

あなたが代わりにMarginプロパティを使用して間接的にこれらの値を設定するプロパティHeightWidthを指定する必要があります。

現在、Marginプロパティは、ボタンがGridに配置されているときの幅と高さを決定します。これは、UIが静的で、ウィンドウのサイズが変更されたときにサイズを変更してはいけない場合に便利です。

あなたはUIが動的にあなたが(あなたがMarginとサイズのために右の値を把握したい場合があります。このような方法で、第二GridRectangleTextBlockButton Sを埋め込む必要があるサイズに適応したいと仮定すると、ボタンの数:

<Grid Margin="137,50,10,10"> 
    <Rectangle x:Name="Exercise_tab_rectangle" Fill="#FFCFC6C6" Stroke="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
    <TextBlock HorizontalAlignment="Stretch" Height="234" Margin="32,37" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Stretch" /> 
    <Button x:Name="Exercise_tab_left_button" Content="&lt;" Margin="11" VerticalAlignment="Center" HorizontalAlignment="Left" Width="20" Height="50" FontSize="18" FontWeight="Bold"/> 
    <Button x:Name="Exercise_tab_Right_button" Content="&gt;" Margin="11" VerticalAlignment="Center" HorizontalAlignment="Right" Width="20" Height="50" FontSize="18" FontWeight="Bold"/> 
</Grid> 
+0

これは完璧に動作し、同時に私に教えてくれてありがとう。非常に高く評価! – Alvaromon

関連する問題