Hello everybody,
I would need to create a component that accepts a row and column layout as input
(2 rows and 2 columns, 3 rows and 3 columns, etc.).
So I took a listview and as itempaneltemplate I use a uniformgrid.
When I add an element to the listview (which is a usercontrol, added via a datatemplate) it is set according to the uniform grid layout.
What I can't implement is that when I set up a layout, I would like the boxes that will then be filled by my user control at runtime to be visible even when the listview is empty.

Sandhiya PriyaRank #26 · 43.2K reputationPosted Oct 29, 2025, 6:04 AM EDT
That’s a great and common UI challenge — and you’re actually close to a good solution. Let’s go step by step.
You’re saying:
You’re using WPF (since you mentioned
UniformGrid,ItemPanelTemplate,UserControl, etc.).You’re binding a
ListViewthat uses aUniformGridin itsItemsPanelTemplate.You want to see all grid “slots” (cells) even when there are no items yet — basically a fixed grid outline with placeholders.
The Core Idea
UniformGriddynamically creates cells only for existing child elements.So if your
ListViewhas no items,UniformGridhas zero children ? hence nothing to show.To show a “visible grid” even when empty, you need placeholder items or a background grid layer that’s always visible.
Approach 1: Pre-Fill Placeholder Items (Recommended)
You can bind your ListView to a collection that always contains the number of placeholders = rows × columns.
When real data arrives, replace placeholders with actual controls.
Example: 3×3 Grid Layout (Always Visible)
XAML
Code-behind (C#)
using System.Collections.ObjectModel; using System.Windows; using System.Windows.Media; namespace GridExample { public partial class MainWindow : Window { public ObservableCollection Cells { get; set; } public MainWindow() { InitializeComponent(); // Example: 3x3 grid (9 placeholders) int rows = 3, cols = 3; Cells = new ObservableCollection(); for (int i = 0; i < rows * cols; i++) { Cells.Add(new GridCell { DisplayText = "Empty", Background = new SolidColorBrush(Color.FromRgb(240, 240, 240)) }); } MyListView.ItemsSource = Cells; } // Example: Fill one cell dynamically later private void Window_Loaded(object sender, RoutedEventArgs e) { // Replace a placeholder with actual data Cells[0].DisplayText = "Data A"; Cells[0].Background = Brushes.LightGreen; } } public class GridCell { public string DisplayText { get; set; } public Brush Background { get; set; } } }How It Works
You initialize placeholders equal to
Rows × Columns.Even when empty, each placeholder cell (with border and “Empty” text) is visible.
Later, you can update any cell with real data (like a user control, image, or live data).
This keeps your grid uniform and visible at all times.
Approach 2: Layer a Grid Background (Alternate)
If you don’t want placeholders in data logic, you can layer a transparent
Grid(background grid lines) behind your ListView using a Grid with Row/ColumnDefinitions.However, that only shows lines — not empty cell spaces that interact with the layout — so Approach 1 is more flexible.
Tip: Dynamic Layout Control
You can make the grid responsive:
int rows = int.Parse(txtRows.Text); int cols = int.Parse(txtCols.Text);Then regenerate placeholders dynamically whenever user changes layout.
Summary