private void replaceVideo(List <VideoControl> videos) { int split = (int)Math.Ceiling(Math.Sqrt(videos.Count)); gridVideo.RowDefinitions.Clear(); gridVideo.ColumnDefinitions.Clear(); for (int i = 0; i < split; i++) { gridVideo.RowDefinitions.Add(new RowDefinition()); gridVideo.ColumnDefinitions.Add(new ColumnDefinition()); } for (int i = 0; i < videos.Count; i++) { int row = i / split; int col = i % split; VideoControl vc = videos[i]; vc.SetValue(Grid.RowProperty, row); vc.SetValue(Grid.ColumnProperty, col); gridVideo.Children.Add(vc); } }