1 changed files with 69 additions and 0 deletions
@ -0,0 +1,69 @@ |
|||
// (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.
|
|||
|
|||
using Avalonia.Controls.Templates; |
|||
using Avalonia.Input; |
|||
using Avalonia.Interactivity; |
|||
using Avalonia.Media; |
|||
using Avalonia.Utilities; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
public class DataGridTemplateColumn : DataGridColumn |
|||
{ |
|||
IDataTemplate _cellTemplate; |
|||
|
|||
public static readonly DirectProperty<DataGridTemplateColumn, IDataTemplate> CellTemplateProperty = |
|||
AvaloniaProperty.RegisterDirect<DataGridTemplateColumn, IDataTemplate>( |
|||
nameof(CellTemplate), |
|||
o => o.CellTemplate, |
|||
(o, v) => o.CellTemplate = v); |
|||
|
|||
public IDataTemplate CellTemplate |
|||
{ |
|||
get { return _cellTemplate; } |
|||
set { SetAndRaise(CellTemplateProperty, ref _cellTemplate, value); } |
|||
} |
|||
|
|||
private void OnCellTemplateChanged(AvaloniaPropertyChangedEventArgs e) |
|||
{ |
|||
//CellTemplateProperty.Changed.AddClassHandler<DataGridTemplateColumn>(x => x.OnCellTemplateChanged);
|
|||
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) |
|||
{ |
|||
return CellTemplate.Build(dataItem); |
|||
} |
|||
if (Design.IsDesignMode) |
|||
{ |
|||
return null; |
|||
} |
|||
else |
|||
{ |
|||
throw DataGridError.DataGridTemplateColumn.MissingTemplateForType(typeof(DataGridTemplateColumn)); |
|||
} |
|||
} |
|||
|
|||
protected override IControl GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding binding) |
|||
{ |
|||
binding = null; |
|||
return GenerateElement(cell, dataItem); |
|||
} |
|||
|
|||
protected override object PrepareCellForEdit(IControl editingElement, RoutedEventArgs editingEventArgs) |
|||
{ |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue