Skip to content

Commit 48f5d03

Browse files
committed
implemented cell and row context flyouts on uno
1 parent 1ca98a2 commit 48f5d03

File tree

4 files changed

+57
-61
lines changed

4 files changed

+57
-61
lines changed

src/TableView.Properties.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public partial class TableView
135135
/// </summary>
136136
public static readonly DependencyProperty AlternateRowBackgroundProperty = DependencyProperty.Register(nameof(AlternateRowBackground), typeof(Brush), typeof(TableView), new PropertyMetadata(null, OnAlternateRowColorChanged));
137137

138-
#if WINDOWS
139138
/// <summary>
140139
/// Identifies the RowContextFlyout dependency property.
141140
/// </summary>
@@ -145,7 +144,6 @@ public partial class TableView
145144
/// Identifies the CellContextFlyout dependency property.
146145
/// </summary>
147146
public static readonly DependencyProperty CellContextFlyoutProperty = DependencyProperty.Register(nameof(CellContextFlyout), typeof(FlyoutBase), typeof(TableView), new PropertyMetadata(null));
148-
#endif
149147
/// <summary>
150148
/// Identifies the ColumnHeaderStyle dependency property.
151149
/// </summary>
@@ -155,7 +153,7 @@ public partial class TableView
155153
/// Identifies the CellStyle dependency property.
156154
/// </summary>
157155
public static readonly DependencyProperty CellStyleProperty = DependencyProperty.Register(nameof(CellStyle), typeof(Style), typeof(TableView), new PropertyMetadata(null, OnCellStyleChanged));
158-
156+
159157
/// <summary>
160158
/// Identifies the CurrentCellSlot dependency property.
161159
/// </summary>
@@ -461,7 +459,6 @@ public Brush AlternateRowForeground
461459
set => SetValue(AlternateRowForegroundProperty, value);
462460
}
463461

464-
#if WINDOWS
465462
/// <summary>
466463
/// Gets or sets the context flyout for rows.
467464
/// </summary>
@@ -479,7 +476,6 @@ public FlyoutBase? CellContextFlyout
479476
get => (FlyoutBase?)GetValue(CellContextFlyoutProperty);
480477
set => SetValue(CellContextFlyoutProperty, value);
481478
}
482-
#endif
483479

484480
/// <summary>
485481
/// Gets or sets the style applied to all column headers.

src/TableView.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,10 @@ internal void EnsureCells()
13491349
}
13501350
#endif
13511351

1352-
#if WINDOWS
13531352
/// <summary>
13541353
/// Shows the context flyout for the specified row.
13551354
/// </summary>
1356-
internal void ShowRowContext(TableViewRow row, Point position)
1355+
internal bool ShowRowContext(TableViewRow row, Point position)
13571356
{
13581357
var eventArgs = new TableViewRowContextFlyoutEventArgs(row.Index, row, row.Content, RowContextFlyout);
13591358
RowContextFlyoutOpening?.Invoke(this, eventArgs);
@@ -1362,19 +1361,25 @@ internal void ShowRowContext(TableViewRow row, Point position)
13621361
{
13631362
var presenter = row.FindDescendant<ListViewItemPresenter>();
13641363

1365-
RowContextFlyout.ShowAt(presenter, new FlyoutShowOptions
1364+
RowContextFlyout.ShowAt(row, new FlyoutShowOptions
13661365
{
1367-
ShowMode = FlyoutShowMode.Standard,
1366+
#if WINDOWS
1367+
ShowMode = FlyoutShowMode.Standard,
1368+
#endif
13681369
Placement = RowContextFlyout.Placement,
13691370
Position = position
13701371
});
1372+
1373+
return true;
13711374
}
1375+
1376+
return false;
13721377
}
13731378

13741379
/// <summary>
13751380
/// Shows the context flyout for the specified cell.
13761381
/// </summary>
1377-
internal void ShowCellContext(TableViewCell cell, Point position)
1382+
internal bool ShowCellContext(TableViewCell cell, Point position)
13781383
{
13791384
var eventArgs = new TableViewCellContextFlyoutEventArgs(cell.Slot, cell, cell.Row?.Content!, CellContextFlyout);
13801385
CellContextFlyoutOpening?.Invoke(this, eventArgs);
@@ -1383,13 +1388,18 @@ internal void ShowCellContext(TableViewCell cell, Point position)
13831388
{
13841389
CellContextFlyout.ShowAt(cell, new FlyoutShowOptions
13851390
{
1386-
ShowMode = FlyoutShowMode.Standard,
1391+
#if WINDOWS
1392+
ShowMode = FlyoutShowMode.Standard,
1393+
#endif
13871394
Placement = CellContextFlyout.Placement,
13881395
Position = position
13891396
});
1397+
1398+
return true;
13901399
}
1400+
1401+
return false;
13911402
}
1392-
#endif
13931403

13941404
/// <summary>
13951405
/// Sets the state of the corner button.
@@ -1460,7 +1470,6 @@ public virtual void OnClearSorting(TableViewClearSortingEventArgs eventArgs)
14601470
/// </summary>
14611471
public event DependencyPropertyChangedEventHandler? IsReadOnlyChanged;
14621472

1463-
#if WINDOWS
14641473
/// <summary>
14651474
/// Event triggered when the row context flyout is opening.
14661475
/// </summary>
@@ -1470,7 +1479,6 @@ public virtual void OnClearSorting(TableViewClearSortingEventArgs eventArgs)
14701479
/// Event triggered when the cell context flyout is opening.
14711480
/// </summary>
14721481
public event EventHandler<TableViewCellContextFlyoutEventArgs>? CellContextFlyoutOpening;
1473-
#endif
14741482

14751483
/// <summary>
14761484
/// Occurs when a sorting is being applied to a column in the TableView.

src/TableViewCell.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,23 @@ public TableViewCell()
4343
#endif
4444
}
4545

46-
#if WINDOWS
46+
47+
#if !WINDOWS
48+
protected override void OnRightTapped(RightTappedRoutedEventArgs e)
49+
{
50+
base.OnRightTapped(e);
51+
52+
var position = e.GetPosition(this);
53+
#else
4754
/// <summary>
4855
/// Handles the ContextRequested event.
4956
/// </summary>
50-
private void OnContextRequested(UIElement sender, ContextRequestedEventArgs args)
57+
private void OnContextRequested(UIElement sender, ContextRequestedEventArgs e)
5158
{
52-
if (TableView is not null && args.TryGetPosition(sender, out var position))
53-
{
54-
TableView.ShowCellContext(this, position);
55-
}
56-
}
59+
if (!e.TryGetPosition(sender, out var position)) return;
5760
#endif
61+
e.Handled = TableView?.ShowCellContext(this, position) is true;
62+
}
5863

5964

6065
/// <summary>
@@ -179,11 +184,11 @@ protected override void OnTapped(TappedRoutedEventArgs e)
179184
{
180185
base.OnTapped(e);
181186

182-
if (TableView?.SelectionUnit is not TableViewSelectionUnit.Row || TableView.CurrentCellSlot != Slot)
183-
{
184-
MakeSelection();
185-
e.Handled = true;
186-
}
187+
if (TableView?.SelectionUnit is not TableViewSelectionUnit.Row || TableView.CurrentCellSlot != Slot)
188+
{
189+
MakeSelection();
190+
e.Handled = true;
191+
}
187192
}
188193

189194
protected override void OnPointerPressed(PointerRoutedEventArgs e)

src/TableViewRow.cs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,22 @@ public TableViewRow()
4848
RegisterPropertyChangedCallback(BackgroundProperty, delegate { OnBackgroundChanged(); });
4949
}
5050

51-
#if WINDOWS
52-
/// <summary>
53-
/// Handles the ContextRequested event.
54-
/// </summary>
55-
private void OnContextRequested(UIElement sender, ContextRequestedEventArgs args)
51+
#if !WINDOWS
52+
protected override void OnRightTapped(RightTappedRoutedEventArgs e)
5653
{
57-
if (args.TryGetPosition(sender, out var position))
58-
{
59-
if (IsContextRequestedFromCell(position) && TableView?.CellContextFlyout is not null) return;
60-
61-
TableView?.ShowRowContext(this, position);
62-
}
63-
}
54+
base.OnRightTapped(e);
6455

56+
var position = e.GetPosition(this);
57+
#else
6558
/// <summary>
66-
/// Determines if the context request is from a cell.
59+
/// Handles the ContextRequested event.
6760
/// </summary>
68-
private bool IsContextRequestedFromCell(Windows.Foundation.Point position)
61+
private void OnContextRequested(UIElement sender, ContextRequestedEventArgs e)
6962
{
70-
if (CellPresenter is null) return false;
71-
72-
var transform = CellPresenter.TransformToVisual(this).Inverse;
73-
var point = transform.TransformPoint(position);
74-
var transformedPoint = CellPresenter.TransformToVisual(null).TransformPoint(point);
75-
return VisualTreeHelper.FindElementsInHostCoordinates(transformedPoint, CellPresenter)
76-
.OfType<TableViewCell>()
77-
.Any();
78-
}
63+
if (!e.TryGetPosition(sender, out var position)) return;
7964
#endif
65+
e.Handled = TableView?.ShowRowContext(this, position) is true;
66+
}
8067

8168
/// <summary>
8269
/// Handles the IsSelected property changed.
@@ -173,10 +160,10 @@ protected override void OnContentChanged(object oldContent, object newContent)
173160
else
174161
{
175162
#endif
176-
foreach (var cell in Cells)
177-
{
178-
cell.RefreshElement();
179-
}
163+
foreach (var cell in Cells)
164+
{
165+
cell.RefreshElement();
166+
}
180167
#if WINDOWS
181168
}
182169
#endif
@@ -510,14 +497,14 @@ internal void EnsureLayout()
510497
#endif
511498
: new Thickness(20, 0, 16, 0);
512499
#if !WINDOWS
513-
var multiSelectSquare = this.FindDescendant<Border>(x => x.Name is "MultiSelectSquare");
514-
if (multiSelectSquare is not null)
515-
{
516-
multiSelectSquare.Opacity = 0.5;
517-
multiSelectSquare.CornerRadius = new CornerRadius(4);
518-
multiSelectSquare.BorderThickness = new Thickness(1);
519-
multiSelectSquare.Margin = new Thickness(10, 0, 0, 0);
520-
}
500+
var multiSelectSquare = this.FindDescendant<Border>(x => x.Name is "MultiSelectSquare");
501+
if (multiSelectSquare is not null)
502+
{
503+
multiSelectSquare.Opacity = 0.5;
504+
multiSelectSquare.CornerRadius = new CornerRadius(4);
505+
multiSelectSquare.BorderThickness = new Thickness(1);
506+
multiSelectSquare.Margin = new Thickness(10, 0, 0, 0);
507+
}
521508
#endif
522509
}
523510
}

0 commit comments

Comments
 (0)