Good day to all! How can I make TabControl scaling when stretching an application window or minimizing / maximizing? Currently scaled horizontally only. Vertically is the standard size (Auto 34).

<Window x:Class="Client.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="4*"></ColumnDefinition> <ColumnDefinition Width="1*"></ColumnDefinition> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" Grid.Row="0"> <TabControl x:Name="mainTab" Margin="0" Height="319"> <TabControl.Effect> <DropShadowEffect/> </TabControl.Effect> <TabItem x:Name="smartphonesTab"> <TabItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Margin="3">Конвертер валют</TextBlock> </StackPanel> </TabItem.Header> </TabItem> <TabItem x:Name="wetherTab"> <TabItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Margin="3">Погода</TextBlock> </StackPanel> </TabItem.Header> </TabItem> <TabItem x:Name="notesTab"> <TabItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Margin="3">Заметки</TextBlock> </StackPanel> </TabItem.Header> </TabItem> </TabControl> </StackPanel> <ListBox x:Name="personList" Grid.Column="1"/> </Grid> 

Screenshot window at startup Stretched window

    2 answers 2

      <TabControl x:Name="mainTab" Margin="0" VerticalAlignment="Stretch" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"> 

    Now it will adjust to the height of the window!

    • Without the Height property, the value in the Auto Properties window (34). - JDo
    • @JDo clean and run the project, I think you will be very surprised! - ParanoidPanda
    • No, I could not be surprised ... A strip of 34 pixels. ! Picture - JDo
    • five
      I do not understand. Doesn't it scale by itself? Just the author stuffed it in the StackPanel and indicated the height, so the car does not work. - vitidev
    • 2
      It's easier to abandon StackPanel - user227049

    As advised in kammentah, this option is more suitable, I think.

     <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="4*"></ColumnDefinition> <ColumnDefinition Width="1*"></ColumnDefinition> </Grid.ColumnDefinitions> <TabControl x:Name="mainTab" Margin="0" VerticalAlignment="Stretch" > <TabControl.Effect> <DropShadowEffect/> </TabControl.Effect> <TabItem x:Name="smartphonesTab"> <TabItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Margin="3">Конвертер валют</TextBlock> </StackPanel> </TabItem.Header> </TabItem> <TabItem x:Name="wetherTab"> <TabItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Margin="3">Погода</TextBlock> </StackPanel> </TabItem.Header> </TabItem> <TabItem x:Name="notesTab"> <TabItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Margin="3">Заметки</TextBlock> </StackPanel> </TabItem.Header> </TabItem> </TabControl> <ListBox x:Name="personList" Grid.Column="1"/> </Grid>