Scale To Fit A Control In WPF

We can set a control to fit a Windows or a panel control by settings its HorizontalAlignment, VertivalAlignment, Width, and Height properties to Stretch, Stretch, Auto, and Auto.

The following code snippet scales a DataGrid to fit to Window on parent Window.

  1. <DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
  2. Height="Auto" Width="Auto" Name="McDataGrid" >