I have the following XAML code (also filled with some dummy content to demonstrate the problem):
<Window x:Class="WpfWatchBird.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="378" Width="728" Name="frmMainList"> <Grid Name="grdMainLayout"> <ListBox Name="lstData" SelectionChanged="lstData_SelectionChanged" HorizontalAlignment="Stretch"> <ListBoxItem HorizontalContentAlignment="Stretch"> <ListBoxItem.Content> <Grid HorizontalAlignment="Stretch"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="25"/> <RowDefinition Height="100"/> <RowDefinition Height="25"/> </Grid.RowDefinitions> <Label Content="nick" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Teal" Grid.Column="0" Grid.Row="0" Margin="0" Padding="0"/> <Label Content="kategória" VerticalAlignment="Center" Foreground="Green" Grid.Column="1" Grid.Row="0" Margin="10,0,0,0" Padding="0"/> <Label Content="stav záznamu" Foreground="Gray" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" Padding="0" Grid.Column="2" Grid.Row="0"/> <Label Content="1.1. 2013 12:00" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,5,0" Padding="0" Grid.Column="3" Grid.Row="0"/> <Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="1" Source="http://www.birdz.sk/la/bezfotky.gif" /> <StackPanel x:Name="spItemText" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="3" HorizontalAlignment="Stretch"> <TextBlock MaxWidth="{Binding ElementName=spItemText,Path=ActualWidth}" FontSize="18" TextWrapping="Wrap"> <TextBlock.Text>Nadpis blogu, konečne, dámy a páni :)</TextBlock.Text> </TextBlock> <TextBlock HorizontalAlignment="Stretch" xml:space="preserve" TextWrapping="Wrap" Margin="10,0,0,0" Padding="0" VerticalAlignment="Top" MaxWidth="{Binding ElementName=spItemText, Path=ActualWidth}"> <TextBlock.Text>Preview textu blogu, blablabla, blabla, bude to pekné a krásne a bude to vedieť robiť aj newliny, len ešte nejak spraviť zarovnanie, aby nebolo... aha, ono nie je, on mi len kvôli xml:space preserve... A už mi aj krásne funguje textwrapping, keď som poodstraňoval zopár nepotrebných ...hmm... tak jeden riadok to wraplo dobre, ale ten ďalší už nie, zaujímavé... </TextBlock.Text> </TextBlock> </StackPanel> <Label Grid.Column="1" Grid.Row="2"> <Hyperlink>Otvor originál</Hyperlink> </Label> <Label Grid.Column="3" Grid.Row="2" HorizontalAlignment="Right"> <Hyperlink>Otvor zložku so zálohou</Hyperlink> </Label> </Grid> </ListBoxItem.Content> </ListBoxItem> <ListBoxItem Content="Menu 2" /> </ListBox> </Grid> </Window>
When growing a window, it changes correctly, but after cutting it refuses to do it. I found this question that seems very close , but I do not consider the answer there as the correct answer (also, I can not comment on the questions / answers, otherwise I would write it there).
The “answer” says that by default ItemsControls are only for growth, but “by default” suggests that there is a way to override this , but the answer does not explain how this is done and I can’t find anything about it ... Any ideas? I would like to do this in XAML, this should be possible without code errors, IMO ...