Skip to content

Commit a888ca3

Browse files
maxkatz6grokys
authored andcommitted
Merge pull request AvaloniaUI#7834 from AvaloniaUI/fixes/touch-date-time-pickers
fix using touch for date/time pickers.
1 parent 582389e commit a888ca3

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Globalization;
33
using System.Linq;
44
using Avalonia.Input;
5+
using Avalonia.Interactivity;
6+
using Avalonia.Media;
57
using Avalonia.VisualTree;
68

79
namespace Avalonia.Controls.Primitives
@@ -58,18 +60,17 @@ public class DateTimePickerPanel : Panel, ILogicalScrollable
5860
private Vector _offset;
5961
private bool _hasInit;
6062
private bool _suppressUpdateOffset;
61-
private ListBoxItem _pressedItem;
6263

6364
public DateTimePickerPanel()
6465
{
6566
FormatDate = DateTime.Now;
66-
AddHandler(ListBoxItem.PointerPressedEvent, OnItemPointerDown, Avalonia.Interactivity.RoutingStrategies.Bubble);
67-
AddHandler(ListBoxItem.PointerReleasedEvent, OnItemPointerUp, Avalonia.Interactivity.RoutingStrategies.Bubble);
67+
AddHandler(TappedEvent, OnItemTapped, RoutingStrategies.Bubble);
6868
}
6969

7070
static DateTimePickerPanel()
7171
{
7272
FocusableProperty.OverrideDefaultValue<DateTimePickerPanel>(true);
73+
BackgroundProperty.OverrideDefaultValue<DateTimePickerPanel>(Brushes.Transparent);
7374
AffectsMeasure<DateTimePickerPanel>(ItemHeightProperty);
7475
}
7576

@@ -523,22 +524,13 @@ private int CoerceSelected(int newValue)
523524
return newValue;
524525
}
525526

526-
private void OnItemPointerDown(object sender, PointerPressedEventArgs e)
527+
private void OnItemTapped(object sender, TappedEventArgs e)
527528
{
528-
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
529+
if (e.Source is IVisual source &&
530+
GetItemFromSource(source) is ListBoxItem listBoxItem &&
531+
listBoxItem.Tag is int tag)
529532
{
530-
_pressedItem = GetItemFromSource((IVisual)e.Source);
531-
e.Handled = true;
532-
}
533-
}
534-
535-
private void OnItemPointerUp(object sender, PointerReleasedEventArgs e)
536-
{
537-
if (e.GetCurrentPoint(this).Properties.PointerUpdateKind == PointerUpdateKind.LeftButtonReleased &&
538-
_pressedItem != null)
539-
{
540-
SelectedValue = (int)GetItemFromSource((IVisual)e.Source).Tag;
541-
_pressedItem = null;
533+
SelectedValue = tag;
542534
e.Handled = true;
543535
}
544536
}

0 commit comments

Comments
 (0)