I have a DataGrid
in a ScrollViewer
. I have one of two problems:
When the width is shrunk and the item text is cut off (the
H2
column isn't wide enough), the scroll bar doesn't appear. However, the two columns that I have are sized appropriately and can't be resized off-screen. The XAML is (basically):<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <DataGrid Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type ScrollViewer}}}"> <DataGrid.Columns> <DataGridTextColumn Header="H1" Width="40" MinWidth="35"/> <DataGridTextColumn Header="H2" Width="*" MinWidth="47"/> </DataGrid.Columns> </DataGrid> </ScrollViewer>
When I have a working scrollbar, the columns can be resized so that the right one can be out of view (the center divider can be moved far enough right that the entire column is out of view). XAML:
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <Grid> <DataGrid Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Grid}}}"> <DataGrid.Columns> <DataGridTextColumn Header="H1" Width="40" MinWidth="35"/> <DataGridTextColumn Header="H2" Width="*" MinWidth="47"/> </DataGrid.Columns> </DataGrid> </Grid> </ScrollViewer>
(Note: in both cases, I have excluded the itemsource
as I don't believe it is necessary for the question, I can add that, as well as the backend code, if needed).
I imagine that this has to do with the element that the DataGrid
is bound to (maybe the Grid
element doesn't resize appropriately, I have tried binding the width of the Grid
to the ScrollViewer
but the problem is the same as (1)).
I have also noticed that the scroll bar does appear (both instances) when the vertical content is cut off and the vertical scroll bar appears (both appear at the same time). Any suggestions to have the scrollbar and ability to ensure that the columns doesn't go off-screen?