Ask a questionAsk a question
 

AnswerI have no clue, how can I resize my Window.

  • Thursday, November 05, 2009 4:44 PMjulian ustiyanovych Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi Folks,

    I just walking around my app. and have no clue how can I implement resizing there.

    min size of window should be 800x600
    max size of window should be 1680x1050

    So, I have a window with AllowsTransparency="True" , but that's not a point.

    I need to know how can I re-size my window by using below method for instance:

     private void Button_Maximize(object sender, RoutedEventArgs e)
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    this.WindowState = WindowState.Normal;
                }
                else
                {
                    this.WindowState = WindowState.Maximized;
                }
            }
    
    thank u in advance,

    julian

Answers

  • Thursday, November 05, 2009 7:29 PMOlaf Rabbachin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Julian,

    you can set the min-/max-size directly in XAML. To do so, set the MinHeight/MinWidth/MaxHeight/MaxWidth properties on the window level (i.e. the root node).
    As for what the other controls do when your window is being resized - the properties I mentioned can be applied to those in just the same way.
    If that doesn't help, try to be more specific.


    Cheers,
    Olaf
  • Wednesday, November 11, 2009 10:49 AMLinda LiuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Julian,

    > My question is, how can I set min/max size directly in code behind.

    You can set the MaxHeight, MaxWidth, MinHeight and MinWidth property of the Window in code as follows:

     private void Button_Maximize(object sender, RoutedEventArgs e)
     {
          if (this.WindowState == WindowState.Maximized)
          {
                    //TODO: here should be code that specify MinHeight and MinWidth
                    this.MinHeight =600;
                        this.MinWidth = 800;
                    this.WindowState = WindowState.Normal;
          }
          else
          {
                    //TODO: here should be code that specify MaxHeight and MaxWidth
                    this.MaxHeight = 1050;
                        this.MaxWidth = 1680;
                    this.WindowState = WindowState.Maximized;
          }
      }

    As rearrange the child controls in the Window when the Window is resized, you can use layout control, e.g. Grid, StackPanel, DockPanel, UniformGrid, etc, to arrage the child controls.

    Hope this helps.

    Sincerely,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Thursday, November 05, 2009 5:05 PMjulian ustiyanovych Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    and what I need to do with all my grids and all other controls, that have hard-coded size ?
  • Thursday, November 05, 2009 7:29 PMOlaf Rabbachin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Julian,

    you can set the min-/max-size directly in XAML. To do so, set the MinHeight/MinWidth/MaxHeight/MaxWidth properties on the window level (i.e. the root node).
    As for what the other controls do when your window is being resized - the properties I mentioned can be applied to those in just the same way.
    If that doesn't help, try to be more specific.


    Cheers,
    Olaf
  • Saturday, November 07, 2009 3:53 PMjulian ustiyanovych Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I can set min/max size directly in xaml, but it's not the point of my question, sorry if it was written not understandable.

    My question is, how can I set min/max size directly in code behind.

     private void Button_Maximize(object sender, RoutedEventArgs e)
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    //TODO: here should be code that specify MinHeight and MinWidth
                    this.WindowState = WindowState.Normal;
                }
    
                else
                {
                    //TODO: here should be code that specify MaxHeight and MaxWidth
                    this.WindowState = WindowState.Maximized;
                }
            }
    
    
     thanks
  • Sunday, November 08, 2009 12:26 PMOlaf Rabbachin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi Julian,

    I'm still uncertain what you might be after. If you don't want users to be able to maximize your window then apply a ResizeMode="NoResize" to your window.
    If you want (parts of) your window's content to be of a fixed size regardless of the window's size, you can setup your content accordingly, i.e. you could wrap your content in a grid. Assuming that you have a control that you always want to have a fixed size of 150 by 150, then I'd wrap this in a 9-cell grid and place the content in the fixed size center cell, i.e.:

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="150"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                   <Button Grid.Row="1" Grid.Column="1" Content="I'll always be 150 by 150"/>
                </Grid>
    
    

    This way, the button would always be centered in your window. That said, you'd probably want to set the MinHeight/MinWidth to 150 as well, in this case.

    If this isn't what you're after, try to describe your scenario or what you'd like to end up with.

    Cheers,
    Olaf
  • Wednesday, November 11, 2009 10:49 AMLinda LiuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Julian,

    > My question is, how can I set min/max size directly in code behind.

    You can set the MaxHeight, MaxWidth, MinHeight and MinWidth property of the Window in code as follows:

     private void Button_Maximize(object sender, RoutedEventArgs e)
     {
          if (this.WindowState == WindowState.Maximized)
          {
                    //TODO: here should be code that specify MinHeight and MinWidth
                    this.MinHeight =600;
                        this.MinWidth = 800;
                    this.WindowState = WindowState.Normal;
          }
          else
          {
                    //TODO: here should be code that specify MaxHeight and MaxWidth
                    this.MaxHeight = 1050;
                        this.MaxWidth = 1680;
                    this.WindowState = WindowState.Maximized;
          }
      }

    As rearrange the child controls in the Window when the Window is resized, you can use layout control, e.g. Grid, StackPanel, DockPanel, UniformGrid, etc, to arrage the child controls.

    Hope this helps.

    Sincerely,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Thursday, November 12, 2009 4:35 PMjulian ustiyanovych Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    WindowStartupLocation="CenterScreen" KeyDown="Window_F1HotKey" Closing="Window_Closing">
        <Window.Resources>
            <FontFamily x:Key="TitleFont">Verdana</FontFamily>
            <System:Double x:Key="Title_Size">24</System:Double>
        </Window.Resources>
        <Viewbox>
        <Border Width="Auto" Height="873" x:Name="windowFrame"
        BorderBrush="DarkOrange" BorderThickness="1,1,1,1"
        CornerRadius="15,15,0,0">
    
                <Border.Background>
                    <LinearGradientBrush >
                        <LinearGradientBrush.GradientStops>
                            <GradientStopCollection>
                                <GradientStop Color="#FFFF5800" Offset="0.0"/>
                                <GradientStop Color="#CEE3FF" Offset="0.5"/>
                            </GradientStopCollection>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Border.Background>
    
                <Grid  ShowGridLines="False" Margin="2,2,2,2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" MinHeight="25"/>
                        <RowDefinition Height="Auto" MinHeight="100"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
    
                    <Grid ShowGridLines="False" Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.904*"/>
                            <ColumnDefinition Width="0.036*"/>
                            <ColumnDefinition Width="0.024*"/>
                            <ColumnDefinition Width="0.036*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock  Text="Upgrade Wizard" Foreground="White" Margin="1,1,27.342,1" 
                    Padding="5" MouseLeftButtonDown="titleBar_MouseLeftButtonDown"/>
                    </Grid>
    
                    <!--LOGO-->
                    <Grid Background="White" ShowGridLines="False" Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Image Source="Images\logo.jpg" Stretch="UniformToFill" Grid.Column="0"/>
    
                        <!--BUTTON MAXIMIZE-->
                        <Button IsEnabled="True" 
                            BorderBrush="Transparent" 
                            Background="Transparent" 
                            HorizontalAlignment="Right" 
                            Margin="0,-28.75,36,0" 
                            Width="31.968" 
                            Height="28.305"
                            Click="Button_Maximize"
                            VerticalAlignment="Top" >
                            <Image Source="Images\IBmaximize.png" 
                               Stretch="Fill" 
                               Height="20.979" 
                               Width="23.31">
                            </Image>
                        </Button>
                        <!--BUTTON MINIMIZE-->
                        <Button BorderThickness="0" 
                            BorderBrush="Transparent" 
                            Background="Transparent" 
                            Margin="0,-28.277,67.532,0" 
                            Click="Button_Minimize" 
                            HorizontalAlignment="Right" 
                            Width="31.968" 
                            Height="29.229" 
                            VerticalAlignment="Top" >
                            <Image Source="Images\IBminimize.png" 
                               Stretch="Fill" 
                               Height="20.979" 
                               Width="23.31" 
                               ToolTip="Minimize">
                            </Image>
                        </Button>
                        <!--BUTTON CLOSE-->
                        <Button Name="btnClose" 
                        BorderBrush="Transparent" 
                        Background="Transparent" 
                        BorderThickness="0"
                        HorizontalAlignment="Right" 
                        Click="Button_Close"  
                        Margin="0,-28.75,4.5,0" 
                        Width="31.968" 
                        Height="29.555" 
                        VerticalAlignment="Top">
                            <Image Source="Images\Close2.png" 
                           Stretch="Fill" 
                           Height="20.979" 
                           Width="23.31" 
                           HorizontalAlignment="Center" 
                           ToolTip="Close">
                            </Image>
                        </Button>
                    </Grid>
    
                    <!--CONTENT-->
                    <Grid Background="White" 
                      ShowGridLines="False"  
                      Grid.Row="1" 
                      Margin="0,208.161,0,0" 
                      Grid.RowSpan="2">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="0*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
    
                        <!--MAIN TAB MENU-->
                        <TabControl x:Name="MainTabControl"
                                Background="Transparent" 
    			                BorderThickness="0" 
                                Grid.RowSpan="2" 
                                SelectionChanged="MainTabControl_SelectionChanged" >
    							
                            <!--WELCOME MENU-->
                            <TabItem Margin="1,3,0,-3" 
                                 FontSize="11"   
                                 Header="Welcome"  
                                 Canvas.ZIndex="3" 
                                 Style="{DynamicResource CustomTabItem}" 
                                 FontWeight="Bold" 
                                 Name="Welcome" 
                                 HorizontalAlignment="Left" 
                                 Width="120">
                                
                                <WelcomeScreen:UCWelcomeScreen
                                             FontSize="11" 
                                             Foreground="Gray" 
                                             FontWeight="Normal" 
                                             >
                                </WelcomeScreen:UCWelcomeScreen>
                            </TabItem>
    
                            <!--QUESTIONAIRE MENU-->
                            <TabItem  Margin="-9,3,-11,-3" 
                                  FontSize="11"  
                                  Header="Questionnaire"  
                                  Canvas.ZIndex="2" 
                                  Style="{DynamicResource CustomTabItem}" 
                                  Name="Questionnaire">
                                <cus:QuestionnarieMenuItem   FontSize="11" 
                                                       Foreground="Gray" 
                                                       FontWeight="Normal" 
                                                       >
                                </cus:QuestionnarieMenuItem>
                            </TabItem>
                            <!--PRE-CHECK MENU-->
                            <TabItem Margin="-18,3,18,-3" 
                                 FontSize="11"  
                                 Header="Pre-Check"  
                                 Canvas.ZIndex="1"  
                                 Style="{DynamicResource CustomTabItem}" 
                                 Name="Precheck">
                                <cus:UCConfigurationMenuItem  
                                BorderThickness="0,0,0,0" 
                                BorderBrush="Transparent"  
                                FontSize="11" 
                                Foreground="Gray" 
                                FontWeight="Normal" 
                                Margin="1,1,1,1" 
                                Height="592.163">
                                </cus:UCConfigurationMenuItem>
                            </TabItem>
    
                            <!--MIG MENU-->
                            <TabItem Name="Migration"  
                                 Margin="-28,2.593,28,-2.593" 
                                 FontSize="11" 
                                 Header="Data Mig" 
                                 Canvas.ZIndex="-2" 
                                 Style="{DynamicResource CustomTabItem}">
                                <cus:UCMigrMenuItem  FontSize="11" Foreground="Gray" FontWeight="Normal"/>
                            </TabItem>
                            <!--CHECKLIST MENU-->
                            <TabItem Name="Checklist"  
                                 Margin="-36.325,2.593,36.325,-2.593" 
                                 FontSize="11" 
                                 Header="Checklist" 
                                 Canvas.ZIndex="-3" 
                                 Style="{DynamicResource CustomTabItem}">
                                <cus:UCCheckListMenuItem FontSize="11" Foreground="Gray" FontWeight="Normal" Margin="0,0,58.831,0"/>
                            </TabItem>
                        </TabControl>
                    </Grid>
                </Grid>
            </Border>
        </Viewbox>
    </Window>
    
    


    Thank you in advance,
    Julian