开发者

Why won't my WPF controls scale when my window is maximized via touching the top of the screen in Windows 7?

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜