Add Content property
This commit is contained in:
Родитель
aa1926943a
Коммит
0f4ffd7b91
|
@ -7,6 +7,9 @@ namespace TemplatedDataGrid
|
|||
{
|
||||
public class DataGridCell : TemplatedControl
|
||||
{
|
||||
public static readonly StyledProperty<object?> ContentProperty =
|
||||
AvaloniaProperty.Register<DataGridCell, object?>(nameof(Content));
|
||||
|
||||
public static readonly StyledProperty<IDataTemplate?> CellTemplateProperty =
|
||||
AvaloniaProperty.Register<DataGridCell, IDataTemplate?>(nameof(CellTemplate));
|
||||
|
||||
|
@ -16,5 +19,13 @@ namespace TemplatedDataGrid
|
|||
get => GetValue(CellTemplateProperty);
|
||||
set => SetValue(CellTemplateProperty, value);
|
||||
}
|
||||
|
||||
[Content]
|
||||
[DependsOn(nameof(CellTemplate))]
|
||||
public object? Content
|
||||
{
|
||||
get { return GetValue(ContentProperty); }
|
||||
set { SetValue(ContentProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace TemplatedDataGrid
|
|||
var cell = new DataGridCell()
|
||||
{
|
||||
[Grid.ColumnProperty] = columnDefinitions.Count - 1,
|
||||
[!DataGridCell.ContentProperty] = this[!DataGridRow.DataContextProperty],
|
||||
[!DataGridCell.CellTemplateProperty] = templateColumn[!DataGridTemplateColumn.CellTemplateProperty]
|
||||
};
|
||||
_rootChildren.Add(cell);
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
<Style Selector="g|DataGridCell">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<ContentControl Content="{Binding}"
|
||||
<ContentControl Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding CellTemplate}"/>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
|
Загрузка…
Ссылка в новой задаче