Defining columns
You can let TableView generate columns automatically from the data source, or define them explicitly in XAML or code.
When to use it
- Use auto-generated columns for rapid prototyping or admin-style UIs where every property should appear as a column.
- Use explicit columns when you need to control the column order, use specific column types, set headers, widths, or configure sorting and filtering per column.
Auto-generated columns
Set AutoGenerateColumns="True" (the default). The control inspects the public properties of the first item in the source and creates one column per property. The column type is chosen based on the property type:
| Property type | Generated column type |
|---|---|
string |
TableViewTextColumn |
numeric types (int, double, etc.) |
TableViewNumberColumn |
bool |
TableViewCheckBoxColumn |
DateOnly, DateTime, DateTimeOffset |
TableViewDateColumn |
TimeOnly, TimeSpan |
TableViewTimeColumn |
Uri |
TableViewHyperlinkColumn |
| Other | TableViewTextColumn |
<tv:TableView ItemsSource="{x:Bind Products}" AutoGenerateColumns="True" />
Handling AutoGeneratingColumn
Use the AutoGeneratingColumn event to customize or cancel individual columns:
tableView.AutoGeneratingColumn += (s, e) =>
{
// Skip the Id property
if (e.PropertyName == "Id")
{
e.Cancel = true;
return;
}
// Rename the header
if (e.PropertyName == "Price")
{
e.Column.Header = "Unit Price ($)";
}
};
TableViewAutoGeneratingColumnEventArgs properties:
| Property | Description |
|---|---|
PropertyName |
Name of the data property |
PropertyType |
Runtime type of the property |
Column |
The column being generated; you can replace it with a different column instance |
Cancel |
Set true to skip this column |
Explicit columns
Set AutoGenerateColumns="False" and populate TableView.Columns in XAML:
<tv:TableView ItemsSource="{x:Bind Products}" AutoGenerateColumns="False">
<tv:TableView.Columns>
<tv:TableViewTextColumn Header="Product Name" Binding="{Binding Name}" Width="200" />
<tv:TableViewNumberColumn Header="Price" Binding="{Binding Price}" Width="100" />
<tv:TableViewCheckBoxColumn Header="In Stock" Binding="{Binding InStock}" Width="80" />
</tv:TableView.Columns>
</tv:TableView>
Column order
Columns render in the order they appear in TableView.Columns. You can also set the Order property on any column to explicitly control its position:
<tv:TableViewTextColumn Header="Name" Binding="{Binding Name}" Order="0" />
<tv:TableViewTextColumn Header="SKU" Binding="{Binding Sku}" Order="2" />
Columns without an explicit Order fall after columns that have one.
Adding columns in code
tableView.Columns.Add(new TableViewTextColumn
{
Header = "Name",
Binding = new Binding { Path = new PropertyPath("Name") }
});
Common column properties
These properties are available on every column type (TableViewColumn base class):
| Property | Type | Description |
|---|---|---|
Header |
object |
Column header content |
Width |
GridLength |
Column width (Auto, *, or pixel value) |
MinWidth |
double? |
Minimum column width |
MaxWidth |
double? |
Maximum column width |
IsReadOnly |
bool |
Overrides TableView.IsReadOnly for this column |
CanSort |
bool |
Whether this column can be sorted |
CanFilter |
bool |
Whether this column can be filtered |
CanResize |
bool |
Whether users can resize this column |
CanReorder |
bool |
Whether users can drag this column to a new position |
Visibility |
Visibility |
Show or hide the column |
Order |
int? |
Display order override |
Tag |
object |
Custom tag object |
HeaderStyle |
Style |
Style for the column header |
CellStyle |
Style |
Style applied to every cell in this column |
IsAutoGenerated |
bool |
true when the column was created by AutoGenerateColumns |
Notes and limitations
AutoGenerateColumnsand explicitColumnsare mutually exclusive. SettingAutoGenerateColumns="False"and also populatingColumnsin XAML is the standard pattern for explicit definitions.- You can mix auto-generated and manually added columns: set
AutoGenerateColumns="True", handleAutoGeneratingColumnto cancel certain properties, and then add custom columns in code. - Columns are not virtualized; all column header controls are created even if they are off-screen horizontally.