Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with the datagrid in the code below growing outside the parent window boundaries. Eventually, the vertical scroll bar appears but extends well below the parent window. I have searched and found that this is a common problem and has been for years? The only solution I've found is to try different parent types etc. This seems like a bug to me. Is MS no longer actively supporting WPF?

Thanks for your help

<window x:class="wpfPollingFileWatcher.MainWindow" xmlns:x="#unknown">
Title="MainWindow" Height="475" Width="675">
<local:changeviewmodel xmlns:local="#unknown">

<rowdefinition height="0.5*">
<rowdefinition height="0.5*">

<grid grid.row="0">
<rowdefinition height="Auto">
<rowdefinition height="Auto">

<stackpanel orientation="Horizontal" grid.row="0">
<Button Name="AddButton" Content="Add" Margin="5" Width="40" HorizontalAlignment="Left"/>
<Button Name="DelButton" Content="Del" Margin="5" Width="40" HorizontalAlignment="Left"/>

<scrollviewer verticalscrollbarvisibility="Auto" grid.row="1">
<datagrid name="WatchesDataGrid" height="Auto">

<grid grid.row="1">
<rowdefinition height="Auto">
<rowdefinition height="Auto">

<Button Name="ClearButton" Content="Clear" Grid.Row="0" Width="40" Margin="5,5,0,5" HorizontalAlignment="Left" Command="{Binding AddChange}" Grid.ColumnSpan="2"/>
<datagrid name="ChangesDataGrid" grid.row="1" height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}" itemssource="{Binding Changes}">
ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="0,0,0,8" HorizontalContentAlignment="Stretch" Grid.ColumnSpan="3"/>

SteveHolle 13-May-15 10:45am    
I found the answer to my question above. To keep the datagrid within the boundaries of the parent control, the row height that the datagrid is placed in must be set to Height="*" not Height="Auto".
Sergey Alexandrovich Kryukov 13-May-15 11:13am    
That's correct. "Auto" is somewhat misleading; it means "the size is defined by child content".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900