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>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.2-build5800-beta" />
<PackageReference Include="Avalonia" Version="0.6.2-*" />
</ItemGroup>
<ItemGroup>
<Compile Update="**\*.xaml.cs">

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

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

13
src/Avalonia.DataGrid/DataGrid.cs

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

85
src/Avalonia.DataGrid/DataGridCell.cs

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

47
src/Avalonia.DataGrid/EventArgs.cs

@ -3,6 +3,7 @@
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using Avalonia.Input;
using Avalonia.Interactivity;
using System;
using System.ComponentModel;
@ -171,6 +172,52 @@ namespace Avalonia.Controls
#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>
/// Provides information just before a cell exits editing mode.
/// </summary>

Loading…
Cancel
Save