storm
storm

Reputation: 11

Resizing window sizes in WPF after orientation and sizeToContent changes

I am having a problem when it comes to going from Horizontal orientation to Vertical orientation and back to Horizontal on a stackpanel with the window SizeToContent property being changed as well. Here's my problem: whenever I go back and forth from vertical to horizontal or vice versa, I change the sizetocontent given the way the menu i am creating as to be done. However, i can't get the window to resize back to an appropriate size as before. For example: State A: this.SizeToContent = Manual this.topLevelStackPanel.Orientation = Horizontal

State B this.SizeToContent = WidthAndHeight this.topLevelStackPanel.Orientation = Vertical

When state A is valid, the restore bounds for the window has this value: 22,29,960,22 When i go from A to B, the restore bounds changes to -1932, -532, 3212, 1092 Now i attempt to go back fro B to A, and the restore bounds don't get changed back to 22,29,960,22

Rather what I get is a huge window that covers up my screen. How do I reset the sizes and go back to the prior state. I have been stuck on this for a while now.

Here's my XAML

<Window.Background>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF528ab5" Offset="0"/>
        <GradientStop Color="#FF002d62" Offset="1"/>
    </LinearGradientBrush>
</Window.Background>
<Window.ContextMenu>
    <ContextMenu>
  <MenuItem Header="Exit" Click="ExitContextMenuItem_Click" />
    </ContextMenu>
</Window.ContextMenu>

<Window.BorderBrush>
    <SolidColorBrush />
</Window.BorderBrush>




        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Name="settingsExitStackPanel">
            <Image x:Name="SettingsButton" HorizontalAlignment="Left" Source="Images/gear_icon.png" MouseDown="SettingsButton_MouseDown"/>
            <TextBlock x:Name="pholder" Text="  " />
            <Button x:Name="ExitButton" Content="X" Width="30" FontWeight="Bold" Click="ExitContextMenuItem_Click"/>
            <TextBlock x:Name="pholder2" Text=" " />
        </StackPanel>

    </Grid>

Upvotes: 1

Views: 817

Answers (0)

Related Questions