You could use ToggleButton to change the window size and restore the size. For displaying Button, HorizontalAlignment and VerticalAlignment in Grid default to Center. And you could edit other controls first in the code and edit Button last. You can try to refer to the following code.
The code of xaml:
<Window x:Class="WindowSizeAndLocation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WindowSizeAndLocation"
mc:Ignorable="d" Name="window" WindowStyle="None"
Title="Window" Height="450" Width="450">
<Grid Name="grid">
<TextBlock Height="262" Width="100" HorizontalAlignment="Right" VerticalAlignment="Center" Background="Cornsilk">Growth Complete!</TextBlock>
<TextBlock VerticalAlignment="Top" HorizontalAlignment="Center" TextAlignment="Center" Width="100"> hello</TextBlock>
<ToggleButton Width="100" Height="30" Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked">size</ToggleButton>
</Grid>
</Window>
The code of xaml.cs:
private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{
Control control = (Control)sender;
this.window.Width = control.Width;
this.window.Height = control.Height +20;
}
private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
{
this.window.Width = 450;
this.window.Height = 450;
}
The picture of result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.
[3]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html