Browse Source

Merge pull request #18 from jmacato/cellpressedevent

Add CellPointerPressed event + Make avalonia reference nightly-invariant
pull/2109/head
sdoroff 7 years ago
committed by GitHub
parent
commit
90188a21e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj
  2. 2
      src/Avalonia.DataGrid/Avalonia.DataGrid.csproj
  3. 13
      src/Avalonia.DataGrid/DataGrid.cs
  4. 85
      src/Avalonia.DataGrid/DataGridCell.cs
  5. 47
      src/Avalonia.DataGrid/EventArgs.cs

2
src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.2-build5800-beta" /> <PackageReference Include="Avalonia" Version="0.6.2-*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="**\*.xaml.cs"> <Compile Update="**\*.xaml.cs">

2
src/Avalonia.DataGrid/Avalonia.DataGrid.csproj

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.2-build5800-beta" /> <PackageReference Include="Avalonia" Version="0.6.2-*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

13
src/Avalonia.DataGrid/DataGrid.cs

@ -1246,6 +1246,11 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
public event EventHandler<DataGridCellEditEndingEventArgs> CellEditEnding; public event EventHandler<DataGridCellEditEndingEventArgs> CellEditEnding;
/// <summary>
/// Occurs when cell is mouse-pressed.
/// </summary>
public event EventHandler<DataGridCellPointerPressedEventArgs> CellPointerPressed;
/// <summary> /// <summary>
/// Occurs when the <see cref="P:Avalonia.Controls.DataGridColumn.DisplayIndex" /> /// Occurs when the <see cref="P:Avalonia.Controls.DataGridColumn.DisplayIndex" />
/// property of a column changes. /// property of a column changes.
@ -2222,6 +2227,14 @@ namespace Avalonia.Controls
{ {
CellEditEnding?.Invoke(this, e); CellEditEnding?.Invoke(this, e);
} }
/// <summary>
/// Raises the CellPointerPressed event.
/// </summary>
internal virtual void OnCellPointerPressed(DataGridCellPointerPressedEventArgs e)
{
CellPointerPressed?.Invoke(this, e);
}
/// <summary> /// <summary>
/// Raises the CurrentCellChanged event. /// Raises the CurrentCellChanged event.

85
src/Avalonia.DataGrid/DataGridCell.cs

@ -86,7 +86,7 @@ namespace Avalonia.Controls
OwningGrid.CurrentSlot == OwningRow.Slot; OwningGrid.CurrentSlot == OwningRow.Slot;
} }
} }
private bool IsEdited private bool IsEdited
{ {
get get
@ -95,7 +95,7 @@ namespace Avalonia.Controls
OwningGrid.EditingColumnIndex == ColumnIndex; OwningGrid.EditingColumnIndex == ColumnIndex;
} }
} }
private bool IsMouseOver private bool IsMouseOver
{ {
get get
@ -127,7 +127,7 @@ namespace Avalonia.Controls
UpdatePseudoClasses(); UpdatePseudoClasses();
_rightGridLine = e.NameScope.Find<Rectangle>(DATAGRIDCELL_elementRightGridLine); _rightGridLine = e.NameScope.Find<Rectangle>(DATAGRIDCELL_elementRightGridLine);
if(_rightGridLine != null && OwningColumn == null) if (_rightGridLine != null && OwningColumn == null)
{ {
// Turn off the right GridLine for filler cells // Turn off the right GridLine for filler cells
_rightGridLine.IsVisible = false; _rightGridLine.IsVisible = false;
@ -160,23 +160,22 @@ namespace Avalonia.Controls
//TODO TabStop //TODO TabStop
private void DataGridCell_PointerPressed(PointerPressedEventArgs e) private void DataGridCell_PointerPressed(PointerPressedEventArgs e)
{ {
if(e.MouseButton != MouseButton.Left)
{
return;
}
// OwningGrid is null for TopLeftHeaderCell and TopRightHeaderCell because they have no OwningRow // OwningGrid is null for TopLeftHeaderCell and TopRightHeaderCell because they have no OwningRow
if (OwningGrid != null) if (OwningGrid != null)
{ {
if (!e.Handled) OwningGrid.OnCellPointerPressed(new DataGridCellPointerPressedEventArgs(this, OwningRow, OwningColumn, e));
//if (!e.Handled && OwningGrid.IsTabStop) if (e.MouseButton == MouseButton.Left)
{
OwningGrid.Focus();
}
if (OwningRow != null)
{ {
e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled); if (!e.Handled)
OwningGrid.UpdatedStateOnMouseLeftButtonDown = true; //if (!e.Handled && OwningGrid.IsTabStop)
{
OwningGrid.Focus();
}
if (OwningRow != null)
{
e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled);
OwningGrid.UpdatedStateOnMouseLeftButtonDown = true;
}
} }
} }
} }
@ -262,7 +261,7 @@ namespace Avalonia.Controls
_rightGridLine.Fill = OwningGrid.VerticalGridLinesBrush; _rightGridLine.Fill = OwningGrid.VerticalGridLinesBrush;
} }
bool newVisibility = bool newVisibility =
(OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.Vertical || OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.All) (OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.Vertical || OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.All)
&& (OwningGrid.ColumnsInternal.FillerColumn.IsActive || OwningColumn != lastVisibleColumn); && (OwningGrid.ColumnsInternal.FillerColumn.IsActive || OwningColumn != lastVisibleColumn);
@ -275,7 +274,7 @@ namespace Avalonia.Controls
private void OnOwningColumnSet(DataGridColumn column) private void OnOwningColumnSet(DataGridColumn column)
{ {
if(column == null) if (column == null)
{ {
Classes.Clear(); Classes.Clear();
} }
@ -303,34 +302,34 @@ namespace Avalonia.Controls
[TemplateVisualState(Name = VisualStates.StateValid, GroupName = VisualStates.GroupValidation)] [TemplateVisualState(Name = VisualStates.StateValid, GroupName = VisualStates.GroupValidation)]
public sealed partial class DataGridCell : ContentControl public sealed partial class DataGridCell : ContentControl
*/ */
//TODO Styles
/// <summary> //TODO Styles
/// Ensures that the correct Style is applied to this object. /// <summary>
/// </summary> /// Ensures that the correct Style is applied to this object.
/// <param name="previousStyle">Caller's previous associated Style</param> /// </summary>
/*internal void EnsureStyle(Style previousStyle) /// <param name="previousStyle">Caller's previous associated Style</param>
/*internal void EnsureStyle(Style previousStyle)
{
if (Style != null
&& (OwningColumn == null || Style != OwningColumn.CellStyle)
&& (OwningGrid == null || Style != OwningGrid.CellStyle)
&& (Style != previousStyle))
{ {
if (Style != null return;
&& (OwningColumn == null || Style != OwningColumn.CellStyle) }
&& (OwningGrid == null || Style != OwningGrid.CellStyle)
&& (Style != previousStyle))
{
return;
}
Style style = null; Style style = null;
if (OwningColumn != null) if (OwningColumn != null)
{ {
style = OwningColumn.CellStyle; style = OwningColumn.CellStyle;
} }
if (style == null && OwningGrid != null) if (style == null && OwningGrid != null)
{ {
style = OwningGrid.CellStyle; style = OwningGrid.CellStyle;
} }
SetStyleWithType(style); SetStyleWithType(style);
} */ } */
} }

47
src/Avalonia.DataGrid/EventArgs.cs

@ -3,6 +3,7 @@
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved. // All other rights reserved.
using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
@ -171,6 +172,52 @@ namespace Avalonia.Controls
#endregion Properties #endregion Properties
} }
/// <summary>
/// Provides information after the cell has been pressed.
/// </summary>
public class DataGridCellPointerPressedEventArgs : EventArgs
{
/// <summary>
/// Instantiates a new instance of this class.
/// </summary>
/// <param name="cell">The cell that has been pressed.</param>
/// <param name="row">The row container of the cell that has been pressed.</param>
/// <param name="column">The column of the cell that has been pressed.</param>
/// <param name="e">The pointer action that has been taken.</param>
public DataGridCellPointerPressedEventArgs(DataGridCell cell,
DataGridRow row,
DataGridColumn column,
PointerPressedEventArgs e)
{
Cell = cell;
Row = row;
Column = column;
PointerPressedEventArgs = e;
}
/// <summary>
/// The cell that has been pressed.
/// </summary>
public DataGridCell Cell { get; }
/// <summary>
/// The row container of the cell that has been pressed.
/// </summary>
public DataGridRow Row { get; }
/// <summary>
/// The column of the cell that has been pressed.
/// </summary>
public DataGridColumn Column { get; }
/// <summary>
/// The pointer action that has been taken.
/// </summary>
public PointerPressedEventArgs PointerPressedEventArgs { get; }
}
/// <summary> /// <summary>
/// Provides information just before a cell exits editing mode. /// Provides information just before a cell exits editing mode.
/// </summary> /// </summary>

Loading…
Cancel
Save