Browse Source

Alter DataGridColumn to use IControl instead of Control

pull/2109/head
sdoroff 7 years ago
parent
commit
cfb013bbf7
  1. 4
      src/Avalonia.DataGrid/DataGrid.cs
  2. 6
      src/Avalonia.DataGrid/DataGridBoundColumn.cs
  3. 10
      src/Avalonia.DataGrid/DataGridCheckBoxColumn.cs
  4. 28
      src/Avalonia.DataGrid/DataGridColumn.cs
  5. 6
      src/Avalonia.DataGrid/DataGridFillerColumn.cs
  6. 18
      src/Avalonia.DataGrid/DataGridTextColumn.cs

4
src/Avalonia.DataGrid/DataGrid.cs

@ -3130,7 +3130,7 @@ namespace Avalonia.Controls
if (EditingRow != null && EditingColumnIndex != -1 && !_executingLostFocusActions)
{
DataGridColumn editingColumn = ColumnsItemsInternal[EditingColumnIndex];
Control editingElement = editingColumn.GetCellContent(EditingRow);
IControl editingElement = editingColumn.GetCellContent(EditingRow);
if (editingElement != null && editingElement.ContainsChild(_focusedObject))
{
Debug.Assert(_lostFocusActions != null);
@ -4564,7 +4564,7 @@ namespace Avalonia.Controls
Debug.Assert(dataGridRow != null);
Debug.Assert(dataGridCell != null);
Control element = null;
IControl element = null;
DataGridBoundColumn dataGridBoundColumn = dataGridColumn as DataGridBoundColumn;
if (isCellEdited)
{

6
src/Avalonia.DataGrid/DataGridBoundColumn.cs

@ -96,9 +96,9 @@ namespace Avalonia.Controls
//TODO Rename
//TODO Validation
protected sealed override Control GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding editBinding)
protected sealed override IControl GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding editBinding)
{
Control element = GenerateEditingElementDirect(cell, dataItem);
IControl element = GenerateEditingElementDirect(cell, dataItem);
editBinding = null;
if (Binding != null)
@ -186,7 +186,7 @@ namespace Avalonia.Controls
*/
protected abstract Control GenerateEditingElementDirect(DataGridCell cell, object dataItem);
protected abstract IControl GenerateEditingElementDirect(DataGridCell cell, object dataItem);
internal AvaloniaProperty BindingTarget { get; set; }

10
src/Avalonia.DataGrid/DataGridCheckBoxColumn.cs

@ -71,7 +71,7 @@ namespace Avalonia.Controls
/// <param name="uneditedValue">
/// The previous, unedited value in the cell being edited.
/// </param>
protected override void CancelCellEdit(Control editingElement, object uneditedValue)
protected override void CancelCellEdit(IControl editingElement, object uneditedValue)
{
if (editingElement is CheckBox editingCheckBox)
{
@ -91,7 +91,7 @@ namespace Avalonia.Controls
/// <returns>
/// A new <see cref="T:System.Windows.Controls.CheckBox" /> control that is bound to the column's <see cref="P:System.Windows.Controls.DataGridBoundColumn.Binding" /> property value.
/// </returns>
protected override Control GenerateEditingElementDirect(DataGridCell cell, object dataItem)
protected override IControl GenerateEditingElementDirect(DataGridCell cell, object dataItem)
{
var checkBox = new CheckBox
{
@ -113,7 +113,7 @@ namespace Avalonia.Controls
/// <returns>
/// A new, read-only <see cref="T:System.Windows.Controls.CheckBox" /> control that is bound to the column's <see cref="P:System.Windows.Controls.DataGridBoundColumn.Binding" /> property value.
/// </returns>
protected override Control GenerateElement(DataGridCell cell, object dataItem)
protected override IControl GenerateElement(DataGridCell cell, object dataItem)
{
bool isEnabled = false;
CheckBox checkBoxElement = new CheckBox();
@ -154,7 +154,7 @@ namespace Avalonia.Controls
/// <returns>
/// The unedited value.
/// </returns>
protected override object PrepareCellForEdit(Control editingElement, RoutedEventArgs editingEventArgs)
protected override object PrepareCellForEdit(IControl editingElement, RoutedEventArgs editingEventArgs)
{
if (editingElement is CheckBox editingCheckBox)
{
@ -206,7 +206,7 @@ namespace Avalonia.Controls
/// Called by the DataGrid control when this column asks for its elements to be
/// updated, because its CheckBoxContent or IsThreeState property changed.
/// </summary>
protected internal override void RefreshCellContent(Control element, string propertyName)
protected internal override void RefreshCellContent(IControl element, string propertyName)
{
if (element == null)
{

28
src/Avalonia.DataGrid/DataGridColumn.cs

@ -36,7 +36,7 @@ namespace Avalonia.Controls
private bool _isVisible;
private object _header;
private DataGridColumnHeader _headerCell;
private Control _editingElement;
private IControl _editingElement;
private ICellEditBinding _editBinding;
private IBinding _clipboardContentBinding;
private readonly Classes _cellStyleClasses = new Classes();
@ -594,7 +594,7 @@ namespace Avalonia.Controls
return content;
}
public Control GetCellContent(DataGridRow dataGridRow)
public IControl GetCellContent(DataGridRow dataGridRow)
{
Contract.Requires<ArgumentNullException>(dataGridRow != null);
if (OwningGrid == null)
@ -606,13 +606,13 @@ namespace Avalonia.Controls
DataGridCell dataGridCell = dataGridRow.Cells[Index];
if (dataGridCell != null)
{
return dataGridCell.Content as Control;
return dataGridCell.Content as IControl;
}
}
return null;
}
public Control GetCellContent(object dataItem)
public IControl GetCellContent(object dataItem)
{
Contract.Requires<ArgumentNullException>(dataItem != null);
if (OwningGrid == null)
@ -633,7 +633,7 @@ namespace Avalonia.Controls
/// <param name="element">element contained in a column</param>
/// <returns>Column that contains the element, or null if not found
/// </returns>
public static DataGridColumn GetColumnContainingElement(Control element)
public static DataGridColumn GetColumnContainingElement(IControl element)
{
// Walk up the tree to find the DataGridCell or DataGridColumnHeader that contains the element
IVisual parent = element;
@ -661,7 +661,7 @@ namespace Avalonia.Controls
/// <param name="uneditedValue">
/// The previous, unedited value in the cell being edited.
/// </param>
protected virtual void CancelCellEdit(Control editingElement, object uneditedValue)
protected virtual void CancelCellEdit(IControl editingElement, object uneditedValue)
{ }
/// <summary>
@ -676,7 +676,7 @@ namespace Avalonia.Controls
/// <returns>
/// A new editing element that is bound to the column's <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.
/// </returns>
protected abstract Control GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding binding);
protected abstract IControl GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding binding);
/// <summary>
/// When overridden in a derived class, gets a read-only element that is bound to the column's
@ -691,7 +691,7 @@ namespace Avalonia.Controls
/// <returns>
/// A new, read-only element that is bound to the column's <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.
/// </returns>
protected abstract Control GenerateElement(DataGridCell cell, object dataItem);
protected abstract IControl GenerateElement(DataGridCell cell, object dataItem);
/// <summary>
/// Called by a specific column type when one of its properties changed,
@ -715,7 +715,7 @@ namespace Avalonia.Controls
/// <returns>
/// The unedited value.
/// </returns>
protected abstract object PrepareCellForEdit(Control editingElement, RoutedEventArgs editingEventArgs);
protected abstract object PrepareCellForEdit(IControl editingElement, RoutedEventArgs editingEventArgs);
/// <summary>
/// Called by the DataGrid control when a column asked for its
@ -723,10 +723,10 @@ namespace Avalonia.Controls
/// </summary>
/// <param name="element">Indicates the element that needs to be refreshed</param>
/// <param name="propertyName">Indicates which property changed and caused this call</param>
protected internal virtual void RefreshCellContent(Control element, string propertyName)
protected internal virtual void RefreshCellContent(IControl element, string propertyName)
{ }
internal void CancelCellEditInternal(Control editingElement, object uneditedValue)
internal void CancelCellEditInternal(IControl editingElement, object uneditedValue)
{
CancelCellEdit(editingElement, uneditedValue);
}
@ -834,12 +834,12 @@ namespace Avalonia.Controls
SetWidthInternalNoCallback(CoerceWidth(Width));
}
internal Control GenerateElementInternal(DataGridCell cell, object dataItem)
internal IControl GenerateElementInternal(DataGridCell cell, object dataItem)
{
return GenerateElement(cell, dataItem);
}
internal object PrepareCellForEditInternal(Control editingElement, RoutedEventArgs editingEventArgs)
internal object PrepareCellForEditInternal(IControl editingElement, RoutedEventArgs editingEventArgs)
{
var result = PrepareCellForEdit(editingElement, editingEventArgs);
editingElement.Focus();
@ -988,7 +988,7 @@ namespace Avalonia.Controls
}
//TODO Binding
internal Control GenerateEditingElementInternal(DataGridCell cell, object dataItem)
internal IControl GenerateEditingElementInternal(DataGridCell cell, object dataItem)
{
if (_editingElement == null)
{

6
src/Avalonia.DataGrid/DataGridFillerColumn.cs

@ -51,18 +51,18 @@ namespace Avalonia.Controls
return headerCell;
}
protected override Control GenerateElement(DataGridCell cell, object dataItem)
protected override IControl GenerateElement(DataGridCell cell, object dataItem)
{
return null;
}
protected override Control GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding editBinding)
protected override IControl GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding editBinding)
{
editBinding = null;
return null;
}
protected override object PrepareCellForEdit(Control editingElement, RoutedEventArgs editingEventArgs)
protected override object PrepareCellForEdit(IControl editingElement, RoutedEventArgs editingEventArgs)
{
return null;
}

18
src/Avalonia.DataGrid/DataGridTextColumn.cs

@ -168,7 +168,7 @@ namespace Avalonia.Controls
/// </summary>
/// <param name="editingElement">The element that the column displays for a cell in editing mode.</param>
/// <param name="uneditedValue">The previous, unedited value in the cell being edited.</param>
protected override void CancelCellEdit(Control editingElement, object uneditedValue)
protected override void CancelCellEdit(IControl editingElement, object uneditedValue)
{
if (editingElement is TextBox textBox)
{
@ -183,7 +183,7 @@ namespace Avalonia.Controls
/// <param name="cell">The cell that will contain the generated element.</param>
/// <param name="dataItem">The data item represented by the row that contains the intended cell.</param>
/// <returns>A new <see cref="T:Avalonia.Controls.TextBox" /> control that is bound to the column's <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.</returns>
protected override Control GenerateEditingElementDirect(DataGridCell cell, object dataItem)
protected override IControl GenerateEditingElementDirect(DataGridCell cell, object dataItem)
{
var textBox = new TextBox
{
@ -222,11 +222,13 @@ namespace Avalonia.Controls
/// <param name="cell">The cell that will contain the generated element.</param>
/// <param name="dataItem">The data item represented by the row that contains the intended cell.</param>
/// <returns>A new, read-only <see cref="T:Avalonia.Controls.TextBlock" /> element that is bound to the column's <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.</returns>
protected override Control GenerateElement(DataGridCell cell, object dataItem)
protected override IControl GenerateElement(DataGridCell cell, object dataItem)
{
TextBlock textBlockElement = new TextBlock();
textBlockElement.Margin = new Thickness(4);
textBlockElement.VerticalAlignment = VerticalAlignment.Center;
TextBlock textBlockElement = new TextBlock
{
Margin = new Thickness(4),
VerticalAlignment = VerticalAlignment.Center
};
if (IsSet(FontFamilyProperty))
{
@ -262,7 +264,7 @@ namespace Avalonia.Controls
/// <param name="editingElement">The element that the column displays for a cell in editing mode.</param>
/// <param name="editingEventArgs">Information about the user gesture that is causing a cell to enter editing mode.</param>
/// <returns>The unedited value. </returns>
protected override object PrepareCellForEdit(Control editingElement, RoutedEventArgs editingEventArgs)
protected override object PrepareCellForEdit(IControl editingElement, RoutedEventArgs editingEventArgs)
{
if (editingElement is TextBox textBox)
{
@ -291,7 +293,7 @@ namespace Avalonia.Controls
/// Called by the DataGrid control when this column asks for its elements to be
/// updated, because a property changed.
/// </summary>
protected internal override void RefreshCellContent(Control element, string propertyName)
protected internal override void RefreshCellContent(IControl element, string propertyName)
{
if (element == null)
{

Loading…
Cancel
Save