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 PriyaPosted Oct 29, 2025, 10:04 AM
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#)
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:
Then regenerate placeholders dynamically whenever user changes layout.
Summary