I have a user control in WPF with a DataGrid. I am adding this user control to the window inside the TabItem TabControl. The vertical scrollbar does not become visible. I resized the window and it seems like the user control is at full height after considering the height of the DataGrid.
How to create a vertical scroll bar and keep the height of the DataGrid in automatic mode depending on the height available by the height of the user control and window?
EDIT: Main window:
<Window>
<Grid>
<TabControl Name="tc"
SelectionChanged="tc_SelectionChanged">
<TabItem Header="ABC">
<local:uc1 />
</TabItem>
<TabItem Header="DEF">
<local:uc2 />
</TabItem>
</TabControl>
</Grid>
</Window>
User control:
<UserControl>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0"
Grid.Column="0"
Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Button>Add</Button>
<Button>Remove</Button>
<Button>Refresh</Button>
</StackPanel>
<Label Name="lblTopMessage">some message</Label>
<DataGrid Name="dg"
IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}"
Header="Name"
Width="*"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Value}"
Header="Value"
Width="130"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding List}"
Header="List"
Width="*"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
<Grid Grid.Row="0"
Grid.Column="1"
Name="gridTS">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Name="lblNewSource"
Grid.Row="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Center"
Padding="0 5 0 0"
FontWeight="Bold">New Source</TextBlock>
<TextBlock Grid.Row="1"
Grid.Column="0"
Padding="10 10 0 0">Name:</TextBlock>
<TextBlock Grid.Row="2"
Grid.Column="0"
Padding="10 10 0 0">Value:</TextBlock>
<TextBlock Grid.Row="3"
Grid.Column="0"
Padding="10 10 0 0">List:</TextBlock>
<TextBox Grid.Row="1"
Grid.Column="1"
Name="txtName"
IsEnabled="False"></TextBox>
<ComboBox Grid.Row="2"
Grid.Column="1"
Name="cbValue"></ComboBox>
<ListBox Grid.Row="3"
Grid.Column="1"
Name="lbList">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Margin="3 5 0 3"
Content="{Binding Name}"
IsChecked="{Binding IsActive}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Name="btnSave"
Click="btnSave_Click"
Grid.Row="4"
Grid.Column="1">Save</Button>
<TextBlock TextWrapping="WrapWithOverflow"
Name="lblMessage"
Grid.Row="5"
Grid.Column="1"
Margin="0 10 10 0"></TextBlock>
</Grid>
</Grid>
</UserControl>
source
share