Reputation: 143
I am creating an application containing grid with 2 rows. It has a DataGrid in a top row and description area in the bottom row. Now I have 2 problems:
If I do not set the height of the DataGrid specifically, loading approximately more than 100 rows takes longer time. If rows are too many, it takes forever. If I set the height, it loads any number of rows instantly and shows the vertical scroll bar. How can I set the DataGrid to fit into the first row without specifying the height/maxheight properties?
I want to use Horizontal GridSplitter so that I can resize each row. However, it does not work after DataGrid is loaded with rows. It works before loading the rows.
Below is My code:
<ScrollViewer >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.5*" />
<RowDefinition Height="0.5*" />
</Grid.RowDefinitions>
<GridSplitter Panel.ZIndex="1"
ResizeDirection="Rows"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Grid.Row="1"
Grid.Column="1"
Height="2"
Background="#c0c0c0" />
<StackPanel Grid.Row="0">
<DataGrid
Margin="10"
Name="EventLogsDataGrid"
IsReadOnly="False"
SelectionChanged="EventLogsDataGrid_OnSelectionChanged"
AutoGenerateColumns="False"
CanUserSortColumns="False"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ColumnWidth="*"
MaxHeight="500"
IsSynchronizedWithCurrentItem="True"
CanUserAddRows="False"
CanUserResizeRows="True"
VerticalAlignment="Stretch"
CanUserDeleteRows="False" />
</StackPanel>
<StackPanel Grid.Row="1">
<Label Content="Description" Margin="5 0 0 0"/>
</StackPanel>
</Grid>
</ScrollViewer>
I have tried setting the DataGrid HorizontalAlignment to Stretch. I have also tried to use the binding to set the height of the DataGrid to the parent element but it did not work.
Upvotes: 0
Views: 313
Reputation: 128061
A StackPanel grows as large as its child elements want, which means that your DataGrid expands to is maximum height. So simply remove the StackPanel and add the DataGrid as direct child of the Grid. Also remove the other StackPanel, since it is also pointless.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridSplitter .../>
<DataGrid Grid.Row="0" ... />
<Label Grid.Row="1" ... />
</Grid>
Upvotes: 3