|
|
|
@ -4,6 +4,7 @@ using Avalonia.Controls.Shapes; |
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Layout; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Globalization; |
|
|
|
@ -398,18 +399,27 @@ namespace Avalonia.Controls |
|
|
|
private void OnFlyoutButtonClicked(object? sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
if (_presenter == null) |
|
|
|
throw new InvalidOperationException("No DatePickerPresenter found"); |
|
|
|
throw new InvalidOperationException("No DatePickerPresenter found."); |
|
|
|
if (_popup == null) |
|
|
|
throw new InvalidOperationException("No Popup found."); |
|
|
|
|
|
|
|
_presenter.Date = SelectedDate ?? DateTimeOffset.Now; |
|
|
|
|
|
|
|
_popup!.IsOpen = true; |
|
|
|
_popup.PlacementMode = PlacementMode.AnchorAndGravity; |
|
|
|
_popup.PlacementAnchor = Primitives.PopupPositioning.PopupAnchor.Bottom; |
|
|
|
_popup.PlacementGravity = Primitives.PopupPositioning.PopupGravity.Bottom; |
|
|
|
_popup.PlacementConstraintAdjustment = Primitives.PopupPositioning.PopupPositionerConstraintAdjustment.SlideY; |
|
|
|
_popup.IsOpen = true; |
|
|
|
|
|
|
|
// Overlay popup hosts won't get measured until the next layout pass, but we need the
|
|
|
|
// template to be applied to `_presenter` now. Detect this case and force a layout pass.
|
|
|
|
if (!_presenter.IsMeasureValid) |
|
|
|
(VisualRoot as ILayoutRoot)?.LayoutManager?.ExecuteInitialLayoutPass(); |
|
|
|
|
|
|
|
var deltaY = _presenter.GetOffsetForPopup(); |
|
|
|
|
|
|
|
// The extra 5 px I think is related to default popup placement behavior
|
|
|
|
_popup!.Host!.ConfigurePosition(_popup.PlacementTarget!, PlacementMode.AnchorAndGravity, new Point(0, deltaY + 5), |
|
|
|
Primitives.PopupPositioning.PopupAnchor.Bottom, Primitives.PopupPositioning.PopupGravity.Bottom, |
|
|
|
Primitives.PopupPositioning.PopupPositionerConstraintAdjustment.SlideY); |
|
|
|
_popup.VerticalOffset = deltaY + 5; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void OnSelectedDateChanged(object? sender, DatePickerSelectedValueChangedEventArgs e) |
|
|
|
|