0

I have a window that has 2 buttons that when clicked they change the size of my window, however when the size is changed the window stops being in the center

How can I keep my window in the center regardless of size

Xaml Code:

Title="MainWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen" ShowInTaskbar="False">
    <Grid>
        <Button Content="1024x768" HorizontalAlignment="Left" Height="60" Margin="210,135,0,0" VerticalAlignment="Top" Width="180" Click="Button_Click"/>
        <Button Content="1280x720" HorizontalAlignment="Left" Height="60" Margin="440,135,0,0" VerticalAlignment="Top" Width="205" Click="Button_Click_1"/>
    </Grid>

CS Code:

private void Button_Click(object sender, RoutedEventArgs e)
{
    Width = 1024;
    Height = 768;
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    Width = 1280;
    Height = 720;
}

0 Answers0