I have an application that repeatedly switches between usercontrols, I want them to stretch to the maximum window size, but something prevented them from doing this, taking at least a minimum amount of space.
I noticed that my components inside usercontrols are changing the way they should (i.e. the buttons locked at the bottom of the control remain in place, the control simply does not reach the bottom of the window where the buttons should end up) I did not set any size-related property properties (I tried several, but none of them had the desired effect). Therefore, I assume that the problem is with the main component that displays the controls. It is configured as follows:
<Window.Resources> <DataTemplate DataType="{x:Type vm:MessageViewModel}"> <vw:MessageView/> </DataTemplate> <DataTemplate DataType="{x:Type vm:ConnectionsViewModel}"> <vw:ConnectionView/> </DataTemplate> ... </Window.Resources> <Grid> <ItemsControl ItemsSource="{Binding ViewModels}" Margin="0,20,0,0"/> ... </Grid>
The solution I used thanks to Erno:
Change
<ItemsControl ItemsSource="{Binding ViewModels}" Margin="0,20,0,0"/>
to
<ItemsControl ItemsSource="{Binding ViewModels}" Margin="0,20,0,0"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl>
source share