Danny

Danny

  • NA
  • 5
  • 5.9k

How do I make all the controls adapt to the screen? WPF

Feb 3 2013 5:04 PM
So after I've done placing all the controls on the Grid, I realised it was a bad idea.

This is my XAML:

<Window x:Class="WordGuru.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="720" Width="1200" WindowStyle="None" >
    <Grid>
        <Label Content="Game Word" HorizontalAlignment="Left" Margin="90,57,0,0" VerticalAlignment="Top" Height="64" Width="221" FontSize="48" FontFamily="Agency FB" FontWeight="Bold"/>
        <Label Content="Find Word" HorizontalAlignment="Left" Margin="112,126,0,0" VerticalAlignment="Top" Height="64" Width="173" FontSize="48" FontFamily="Agency FB" FontWeight="Bold"/>
        <Image Name="Smiley" HorizontalAlignment="Left" Height="256" Margin="311,232,0,0" VerticalAlignment="Top" Width="256" Source="RightSmile.png"/>
        <TextBox Name="GameWord" HorizontalAlignment="Left" Height="64" Margin="311,56,0,0" TextWrapping="Wrap" Text="ASDOJENALFJ" VerticalAlignment="Top" Width="327" FontFamily="Agency FB" FontSize="48" BorderBrush="Black" BorderThickness="4" IsReadOnly="True" />
        <TextBox Name="WordInput" HorizontalAlignment="Left" Height="64" Margin="311,125,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="327" FontFamily="Agency FB" FontSize="48" BorderBrush="Black" BorderThickness="4" KeyDown="WordInput_KeyDown" CharacterCasing="Upper"/>
        <ListBox Name="CorrWord" HorizontalAlignment="Left" Height="496" Margin="712,57,0,0" VerticalAlignment="Top" Width="334" BorderBrush="Black" BorderThickness="4" FontFamily="Agency FB" FontSize="36" >
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="IsEnabled" Value="False"/>
                    <Style.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="Red" />
                        </Trigger>


                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
        <TextBox Name="CountDown" Height="57" Margin="394,496,731.6,0" TextWrapping="Wrap" VerticalAlignment="Top" BorderBrush="White" FontFamily="Agency FB" FontSize="56" FontWeight="Bold" Text="Time" IsReadOnly="True" Background="{x:Null}" BorderThickness="0"/>
        <TextBox Height="57" Margin="112,496,784.6,0" TextWrapping="Wrap" Text="Time remaining:" VerticalAlignment="Top" BorderBrush="White" FontFamily="Agency FB" FontSize="48" IsReadOnly="True" Background="{x:Null}" BorderThickness="0" FontWeight="Bold"/>
        <ProgressBar Name="TBar" Value="30" Maximum="30" HorizontalAlignment="Left" Height="48" Margin="90,597,0,0" VerticalAlignment="Top" Width="956"/>
    </Grid>
</Window>

How should I do now to make it automatically resize depending on window size? I don't know where to start...

Thanks!

Answers (2)