简体   繁体   中英

My buttons wont resize when the window is resized

When i resize the window the buttons dont resize with it, everything else like the websites do but not the buttons. i tried using "border" method but it only fixed resizing the content, the background also works fine.

<Window Title="MainWindow" Height="700" Width="980" 
        Background="Transparent" >
   <Border>
      <Grid MinHeight="1" MinWidth="1">
         <Grid.Background>
            <ImageBrush Stretch="UniformToFill"  ImageSource="images\tarkov wallpaper.jpg"/>
         </Grid.Background>

         <Button x:Name="fleam" Click="flea_click" Background="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Width="245" Height="51" Margin="734,52,0,0" BorderThickness="0" >
            <Image Source="images\flea.png" Height="51" Width="235" Stretch="Fill" />
         </Button>
         <Button x:Name="maps" Click="map_click" Background="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Width="245" Height="51" Margin="491,52,0,0" BorderThickness="0" >
            <Image Source="images\maps.png" Height="51" Width="245" Stretch="Fill" />
         </Button>
         <Button x:Name="ammo" Click="ammo_click" Background="Black"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="245" Height="51" Margin="246,52,0,0" BorderThickness="0" >
            <Image Source="images\ammo.png" Height="51" Width="245" Stretch="Fill" />
         </Button>
         <Button x:Name="armor" Click="armor_click" Background="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Width="245" Height="51" Margin="1,52,0,0" BorderThickness="0" >
            <Image Source="images\armor.png" Height="51" Width="245" Stretch="Fill" />
         </Button>
         <eo:WebControl x:Name="fleamarket" Margin="10,108,10,0" Visibility="Hidden">
            <eo:WebControl.WebView>
               <eo:WebView Url="https://tarkov-market.com/">
               </eo:WebView>
            </eo:WebControl.WebView>
         </eo:WebControl>
         <eo:WebControl x:Name="map" Margin="10,122,-5,10" Visibility="Hidden">
            <eo:WebControl.WebView>
               <eo:WebView Url="https://mapgenie.io/tarkov">
               </eo:WebView>
            </eo:WebControl.WebView>
         </eo:WebControl>
         <eo:WebControl x:Name="ammon" Margin="10,108,10,10" Visibility="Hidden">
            <eo:WebControl.WebView>
               <eo:WebView Url="https://docs.google.com/spreadsheets/d/1_l-gYeSt2MqIw62EdMZt_wefG0yO9L7dTaRM74c2J1w/edit#gid=2023683591" >
               </eo:WebView>
            </eo:WebControl.WebView>
         </eo:WebControl>
         <Image x:Name="armorimg" Source="images/amorcont.jpg" Margin="-18,108,-18,0" Visibility="Hidden"/>
      </Grid>
   </Border>
</Window>

Firstly, try to define rows and columns for your Grid . Secondly, remove the Width and Height properties for your controls. Finally, use Margin property to determine the relative size and position of the controls inside the Grid cells. This code will help you:

<Window Title="MainWindow" Height="120" Width="120">
    <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Button Margin="10">Button 1</Button>
            <Button Grid.Column="1" Margin="10">Button 2</Button>
            <Button Grid.Column="2" Margin="10">Button 3</Button>
            <Button Grid.Row="1" Margin="10">Button 4</Button>
            <Button Grid.Column="1" Grid.Row="1" Margin="10">Button 5</Button>
            <Button Grid.Column="2" Grid.Row="1" Margin="10">Button 6</Button>
            <Button Grid.Row="2" Margin="10">Button 7</Button>
            <Button Grid.Column="1" Grid.Row="2" Margin="10">Button 8</Button>
            <Button Grid.Column="2" Grid.Row="2" Margin="10"Button 9</Button>
        </Grid>
</Window>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM