There is some set of Facts (Title, Text). The user can complement it. I need to place all these facts on the grid. The problem is that it is impossible to calculate the size of the block with the text for its positioning. In the end, everything moves.
void LoadFacts(int FactId) { grid.Children.Clear(); double indent = 0; foreach (Fact fact in facts) { Label title = new Label() { Content = fact.Title, Margin = new Thickness(30, indent, 0, 0), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, FontSize = 20, }; TextBlock text = new TextBlock() { Text = fact.Text, Margin = new Thickness(30, 50 + indent, 0, 0), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, FontSize = 16, TextWrapping = TextWrapping.Wrap, Background = Brushes.AliceBlue, }; text.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); indent += text.DesiredSize.Height; grid.Children.Add(title); grid.Children.Add(text); } grid.Height = indent; } 

BindingandListBoxtype elements with their own style - EvgeniyZ