|
2 | 2 | using System.Globalization;
|
3 | 3 | using System.Linq;
|
4 | 4 | using Avalonia.Input;
|
| 5 | +using Avalonia.Interactivity; |
| 6 | +using Avalonia.Media; |
5 | 7 | using Avalonia.VisualTree;
|
6 | 8 |
|
7 | 9 | namespace Avalonia.Controls.Primitives
|
@@ -58,18 +60,17 @@ public class DateTimePickerPanel : Panel, ILogicalScrollable
|
58 | 60 | private Vector _offset;
|
59 | 61 | private bool _hasInit;
|
60 | 62 | private bool _suppressUpdateOffset;
|
61 |
| - private ListBoxItem _pressedItem; |
62 | 63 |
|
63 | 64 | public DateTimePickerPanel()
|
64 | 65 | {
|
65 | 66 | 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); |
68 | 68 | }
|
69 | 69 |
|
70 | 70 | static DateTimePickerPanel()
|
71 | 71 | {
|
72 | 72 | FocusableProperty.OverrideDefaultValue<DateTimePickerPanel>(true);
|
| 73 | + BackgroundProperty.OverrideDefaultValue<DateTimePickerPanel>(Brushes.Transparent); |
73 | 74 | AffectsMeasure<DateTimePickerPanel>(ItemHeightProperty);
|
74 | 75 | }
|
75 | 76 |
|
@@ -523,22 +524,13 @@ private int CoerceSelected(int newValue)
|
523 | 524 | return newValue;
|
524 | 525 | }
|
525 | 526 |
|
526 |
| - private void OnItemPointerDown(object sender, PointerPressedEventArgs e) |
| 527 | + private void OnItemTapped(object sender, TappedEventArgs e) |
527 | 528 | {
|
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) |
529 | 532 | {
|
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; |
542 | 534 | e.Handled = true;
|
543 | 535 | }
|
544 | 536 | }
|
|
0 commit comments