2

I have a borderless window created for my WPF application. It resizes perfectly on the sides and corners and also when I drag it to the left or right side of the screen it perfectly scales to fit half the screen. If I use a button or other control event to maximize the window it works perfectly. However, when I drag the window to the top of the screen, the actual window maximizes but the grid inside it does not.

I have it set up to call a method on the sizeChanged event that sets the size of the grid relative to the window (it fills the entire window except 10 pixels on each edge). At first, I thought the sizeChanged event wasn't firing so I created a thread to just detect if the windowState was maximized. On detection it would simply run the method to size up the grid. The method ran, but the grid size didn't change. Only this method of maximization is a problem.

How do I fix this problem?

Edit: XAML

 <Window.Background>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF868686" Offset="0" />
        <GradientStop Color="Black" Offset="1" />
    </LinearGradientBrush>
</Window.Background>
<Grid Background="{x:Null}" Name="baseGrid">
    <Grid Height="342" HorizontalAlignment="Stretch" Name="grid1" VerticalAlignment="Stretch" Width="718" Background="#46BA0000">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="6,6,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="maximize" />
    </Grid>
</Grid>

I'm also using a style and a theme in my application but this problem happens even when they aren't involved so i didnt include them in the XAML

user999609
  • 21
  • 1
  • 3

1 Answers1

1

One solution you can try is to put VerticalAlignment="Stretch" and HorizontalAlignment="Stretch" on your grid control

Other solution is to use e.NewSize.Width and e.NewSize.Height to calculate the grid height and width on Window's SizeChanged event handler.

S2S2
  • 8,322
  • 5
  • 37
  • 65
  • changing the alignment types to stretch just make the grid stay in the centre of the window when it maximizes. any other ideas? – user999609 Oct 18 '11 at 18:43
  • @user999609, you'll also need to leave Width and Height as "Auto" (the default value) so that the Grid can automatically resize to fit its container's space. You can use the Margin property to provide a margin relative to the container. – Dan Bryant Oct 18 '11 at 19:12
  • Yes, I agree with @DanBryant, you would also need to set Grid Height and Width to Auto in addition to using Stretch..!! – S2S2 Oct 19 '11 at 04:16
  • I see in your XAML, u have 2 grids, may be u need to set Auto on both the grids, if that doesnt work out; else use 1 column definition and 1 row definition with Height, Width = "*" in each of the grids.. – S2S2 Oct 19 '11 at 15:34