|
|
|
@ -1,4 +1,4 @@ |
|
|
|
// (c) Copyright Microsoft Corporation.
|
|
|
|
// (c) Copyright Microsoft Corporation.
|
|
|
|
// This source is subject to the Microsoft Public License (Ms-PL).
|
|
|
|
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
|
|
|
|
// All other rights reserved.
|
|
|
|
@ -15,7 +15,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
public class DataGridTemplateColumn : DataGridColumn |
|
|
|
{ |
|
|
|
IDataTemplate _cellTemplate; |
|
|
|
private IDataTemplate _cellTemplate; |
|
|
|
|
|
|
|
public static readonly DirectProperty<DataGridTemplateColumn, IDataTemplate> CellTemplateProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<DataGridTemplateColumn, IDataTemplate>( |
|
|
|
@ -30,17 +30,38 @@ namespace Avalonia.Controls |
|
|
|
set { SetAndRaise(CellTemplateProperty, ref _cellTemplate, value); } |
|
|
|
} |
|
|
|
|
|
|
|
private IDataTemplate _cellEditingCellTemplate; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="CellEditingTemplate"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly DirectProperty<DataGridTemplateColumn, IDataTemplate> CellEditingTemplateProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<DataGridTemplateColumn, IDataTemplate>( |
|
|
|
nameof(CellEditingTemplate), |
|
|
|
o => o.CellEditingTemplate, |
|
|
|
(o, v) => o.CellEditingTemplate = v); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the <see cref="IDataTemplate"/> which is used for the editing mode of the current <see cref="DataGridCell"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <value>
|
|
|
|
/// An <see cref="IDataTemplate"/> for the editing mode of the current <see cref="DataGridCell"/>
|
|
|
|
/// </value>
|
|
|
|
/// <remarks>
|
|
|
|
/// If this property is <see langword="null"/> the column is read-only.
|
|
|
|
/// </remarks>
|
|
|
|
public IDataTemplate CellEditingTemplate |
|
|
|
{ |
|
|
|
get => _cellEditingCellTemplate; |
|
|
|
set => SetAndRaise(CellEditingTemplateProperty, ref _cellEditingCellTemplate, value); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnCellTemplateChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
var oldValue = (IDataTemplate)e.OldValue; |
|
|
|
var value = (IDataTemplate)e.NewValue; |
|
|
|
} |
|
|
|
|
|
|
|
public DataGridTemplateColumn() |
|
|
|
{ |
|
|
|
IsReadOnly = true; |
|
|
|
} |
|
|
|
|
|
|
|
protected override IControl GenerateElement(DataGridCell cell, object dataItem) |
|
|
|
{ |
|
|
|
if(CellTemplate != null) |
|
|
|
@ -60,7 +81,22 @@ namespace Avalonia.Controls |
|
|
|
protected override IControl GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding binding) |
|
|
|
{ |
|
|
|
binding = null; |
|
|
|
return GenerateElement(cell, dataItem); |
|
|
|
if(CellEditingTemplate != null) |
|
|
|
{ |
|
|
|
return CellEditingTemplate.Build(dataItem); |
|
|
|
} |
|
|
|
else if (CellTemplate != null) |
|
|
|
{ |
|
|
|
return CellTemplate.Build(dataItem); |
|
|
|
} |
|
|
|
if (Design.IsDesignMode) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw DataGridError.DataGridTemplateColumn.MissingTemplateForType(typeof(DataGridTemplateColumn)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override object PrepareCellForEdit(IControl editingElement, RoutedEventArgs editingEventArgs) |
|
|
|
@ -70,12 +106,30 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
protected internal override void RefreshCellContent(IControl element, string propertyName) |
|
|
|
{ |
|
|
|
if(propertyName == nameof(CellTemplate) && element.Parent is DataGridCell cell) |
|
|
|
var cell = element.Parent as DataGridCell; |
|
|
|
if(propertyName == nameof(CellTemplate) && cell is not null) |
|
|
|
{ |
|
|
|
cell.Content = GenerateElement(cell, cell.DataContext); |
|
|
|
} |
|
|
|
|
|
|
|
base.RefreshCellContent(element, propertyName); |
|
|
|
} |
|
|
|
|
|
|
|
public override bool IsReadOnly |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (CellEditingTemplate is null) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return base.IsReadOnly; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
base.IsReadOnly = value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|