in wpf how do i make a datagrid fit the window height

前端 未结 3 560
清歌不尽
清歌不尽 2020-12-15 05:48

I have a grid with 3 columns and 2 rows

        
            
            

        
3条回答
  •  Happy的楠姐
    2020-12-15 06:22

    Try setting your DataGrid's HorizontalAlignment=Stretch and VerticalScrollBarVisibility=Auto

    If that doesn't work, you may also need to bind the Grid's Height to the Window Height so that it doesn't auto-grow to fit its contents. Usually I use Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}" (It might be RenderSize.ActualHeight instead of just ActualHeight... I forgot.

    Another alternative is to use a DockPanel instead of a Grid since that control doesn't auto-grow to fit its contents. Instead it'll stretch its last child to fill the remaining space.

提交回复
热议问题