The ViewBox will be stretched by setting Stretch="Fill"
and StretchDirection="Both"
, and you can modify the layout to make the controls sized appropriately. It will stretch your control to the same size as the window, leaving no blank space. If I misunderstood your question, please point it out.
The code of xaml:
<Viewbox Stretch="Fill" StretchDirection="Both">
<Grid Background="AliceBlue">
<DataGrid ItemsSource="{Binding MyCollection}" BorderBrush="Black" AutoGenerateColumns="False"
BorderThickness="1"
IsReadOnly="False" CanUserAddRows="True" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Name of person"/>
<DataGridTemplateColumn Header="Age of person" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=DataContext.Source1, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
SelectedValue="{Binding Age}" SelectedValuePath="Number" DisplayMemberPath="Number"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Salary}" Header="Persons salary"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Viewbox>
The picture of result:
Stretch the window longitudinally
Stretch window horizontally
Stretch the window horizontally and vertically at the same time:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.