|
|
|
@ -1,7 +1,9 @@ |
|
|
|
using System; |
|
|
|
using System.Globalization; |
|
|
|
using System.Linq; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Input.GestureRecognizers; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
@ -60,6 +62,7 @@ namespace Avalonia.Controls.Primitives |
|
|
|
private Vector _offset; |
|
|
|
private bool _hasInit; |
|
|
|
private bool _suppressUpdateOffset; |
|
|
|
private ScrollContentPresenter? _parentScroller; |
|
|
|
|
|
|
|
public DateTimePickerPanel() |
|
|
|
{ |
|
|
|
@ -255,6 +258,8 @@ namespace Avalonia.Controls.Primitives |
|
|
|
_suppressUpdateOffset = true; |
|
|
|
SelectedValue = (int)newSel * Increment + MinimumValue; |
|
|
|
_suppressUpdateOffset = false; |
|
|
|
|
|
|
|
System.Diagnostics.Debug.WriteLine($"Offset: {_offset} ItemHeight: {ItemHeight}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -270,7 +275,7 @@ namespace Avalonia.Controls.Primitives |
|
|
|
|
|
|
|
public Size Extent => _extent; |
|
|
|
|
|
|
|
public Size Viewport => new Size(0, ItemHeight); |
|
|
|
public Size Viewport => Bounds.Size; |
|
|
|
|
|
|
|
public event EventHandler? ScrollInvalidated; |
|
|
|
|
|
|
|
@ -341,6 +346,20 @@ namespace Avalonia.Controls.Primitives |
|
|
|
return finalSize; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) |
|
|
|
{ |
|
|
|
base.OnAttachedToVisualTree(e); |
|
|
|
_parentScroller = this.GetVisualParent() as ScrollContentPresenter; |
|
|
|
_parentScroller?.AddHandler(Gestures.ScrollGestureEndedEvent, OnScrollGestureEnded); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) |
|
|
|
{ |
|
|
|
base.OnDetachedFromVisualTree(e); |
|
|
|
_parentScroller?.RemoveHandler(Gestures.ScrollGestureEndedEvent, OnScrollGestureEnded); |
|
|
|
_parentScroller = null; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e) |
|
|
|
{ |
|
|
|
switch (e.Key) |
|
|
|
@ -554,5 +573,15 @@ namespace Avalonia.Controls.Primitives |
|
|
|
{ |
|
|
|
ScrollInvalidated?.Invoke(this, e); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnScrollGestureEnded(object? sender, ScrollGestureEndedEventArgs e) |
|
|
|
{ |
|
|
|
var snapY = Math.Round(Offset.Y / ItemHeight) * ItemHeight; |
|
|
|
|
|
|
|
if (snapY != Offset.Y) |
|
|
|
{ |
|
|
|
Offset = Offset.WithY(snapY); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|