mirror of
https://gitee.com/chinware/atomui.git
synced 2024-11-29 18:38:16 +08:00
Fixed the abnormal dispatching of DatePicker's Hover selection event
Fixed the abnormal dispatching of DatePicker's Hover selection event
This commit is contained in:
parent
a5a2020d06
commit
e21f79e23c
@ -12,7 +12,7 @@
|
||||
<desktop:ShowCaseItem
|
||||
Title="Basic"
|
||||
Description="Click DatePicker, and then we could select or input a date in panel.">
|
||||
<atom:DatePicker Watermark="Select date" SelectedDateTime="2029-9-3" IsNeedConfirm="True"/>
|
||||
<atom:DatePicker Watermark="Select date" DefaultDateTime="2029-9-3" IsNeedConfirm="True"/>
|
||||
</desktop:ShowCaseItem>
|
||||
<!-- -->
|
||||
<!-- <desktop:ShowCaseItem -->
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AtomUI.Controls.Internal;
|
||||
using AtomUI.Controls.CalendarView;
|
||||
using AtomUI.Controls.Internal;
|
||||
using AtomUI.Data;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@ -128,7 +129,35 @@ public class DatePicker : InfoPickerInput
|
||||
return;
|
||||
}
|
||||
|
||||
presenter.ChoosingStatueChanged += (sender, args) =>
|
||||
BindUtils.RelayBind(this, SelectedDateTimeProperty, presenter, DatePickerPresenter.SelectedDateTimeProperty);
|
||||
BindUtils.RelayBind(this, IsNeedConfirmProperty, presenter, DatePickerPresenter.IsNeedConfirmProperty);
|
||||
BindUtils.RelayBind(this, IsShowNowProperty, presenter, DatePickerPresenter.IsShowNowProperty);
|
||||
BindUtils.RelayBind(this, IsShowTimeProperty, presenter, DatePickerPresenter.IsShowTimeProperty);
|
||||
}
|
||||
|
||||
protected override void NotifyFlyoutOpened()
|
||||
{
|
||||
base.NotifyFlyoutOpened();
|
||||
if (_pickerPresenter is not null)
|
||||
{
|
||||
_pickerPresenter.ChoosingStatueChanged += HandleChoosingStatueChanged;
|
||||
_pickerPresenter.HoverDateTimeChanged += HandleHoverDateTimeChanged;
|
||||
_pickerPresenter.Confirmed += HandleConfirmed;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void NotifyFlyoutAboutToClose(bool selectedIsValid)
|
||||
{
|
||||
base.NotifyFlyoutAboutToClose(selectedIsValid);
|
||||
if (_pickerPresenter is not null)
|
||||
{
|
||||
_pickerPresenter.ChoosingStatueChanged -= HandleChoosingStatueChanged;
|
||||
_pickerPresenter.HoverDateTimeChanged -= HandleHoverDateTimeChanged;
|
||||
_pickerPresenter.Confirmed -= HandleConfirmed;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleChoosingStatueChanged(object? sender, ChoosingStatusEventArgs args)
|
||||
{
|
||||
_isChoosing = args.IsChoosing;
|
||||
UpdatePseudoClasses();
|
||||
@ -136,8 +165,9 @@ public class DatePicker : InfoPickerInput
|
||||
{
|
||||
ClearHoverSelectedInfo();
|
||||
}
|
||||
};
|
||||
presenter.HoverDateTimeChanged += (sender, args) =>
|
||||
}
|
||||
|
||||
private void HandleHoverDateTimeChanged(object? sender, DateSelectedEventArgs args)
|
||||
{
|
||||
if (args.Value.HasValue)
|
||||
{
|
||||
@ -147,24 +177,18 @@ public class DatePicker : InfoPickerInput
|
||||
{
|
||||
Text = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
presenter.Confirmed += (sender, args) =>
|
||||
private void HandleConfirmed(object? sender, EventArgs args)
|
||||
{
|
||||
SelectedDateTime = presenter.SelectedDateTime;
|
||||
Dispatcher.UIThread.Post(() => ClosePickerFlyout());
|
||||
};
|
||||
|
||||
BindUtils.RelayBind(this, SelectedDateTimeProperty, presenter, DatePickerPresenter.SelectedDateTimeProperty);
|
||||
BindUtils.RelayBind(this, IsNeedConfirmProperty, presenter, DatePickerPresenter.IsNeedConfirmProperty);
|
||||
BindUtils.RelayBind(this, IsShowNowProperty, presenter, DatePickerPresenter.IsShowNowProperty);
|
||||
BindUtils.RelayBind(this, IsShowTimeProperty, presenter, DatePickerPresenter.IsShowTimeProperty);
|
||||
SelectedDateTime = _pickerPresenter?.SelectedDateTime;
|
||||
ClosePickerFlyout();
|
||||
}
|
||||
|
||||
private void ClearHoverSelectedInfo()
|
||||
{
|
||||
DateTime? targetValue = default;
|
||||
targetValue = SelectedDateTime ?? DefaultDateTime;
|
||||
targetValue = SelectedDateTime;
|
||||
Text = targetValue?.ToString(EffectiveFormat());
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,7 @@ internal class DatePickerPresenter : PickerPresenterBase
|
||||
private Button? _confirmButton;
|
||||
private PickerCalendar? _calendarView;
|
||||
private IDisposable? _choosingStateDisposable;
|
||||
private bool _isConfirmed;
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
@ -112,6 +113,7 @@ internal class DatePickerPresenter : PickerPresenterBase
|
||||
});
|
||||
}
|
||||
|
||||
_isConfirmed = false;
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
@ -165,6 +167,18 @@ internal class DatePickerPresenter : PickerPresenterBase
|
||||
{
|
||||
_confirmButton.Click += HandleConfirmButtonClicked;
|
||||
_confirmButton.IsEnabled = SelectedDateTime is not null;
|
||||
_confirmButton.PointerEntered += (sender, args) =>
|
||||
{
|
||||
if (_calendarView?.SelectedDate is not null)
|
||||
{
|
||||
var hoverDateTime = CollectDateTime(_calendarView?.SelectedDate);
|
||||
HoverDateTimeChanged?.Invoke(this, new DateSelectedEventArgs(hoverDateTime));
|
||||
}
|
||||
};
|
||||
_confirmButton.PointerExited += (sender, args) =>
|
||||
{
|
||||
ChoosingStatueChanged?.Invoke(this, new ChoosingStatusEventArgs(false));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ internal class FlyoutStateHelper : AvaloniaObject
|
||||
public event EventHandler<EventArgs>? FlyoutAboutToClose;
|
||||
public event EventHandler<EventArgs>? FlyoutClosed;
|
||||
public event EventHandler<EventArgs>? FlyoutAboutToShow;
|
||||
public event EventHandler<EventArgs>? FlyoutOpened;
|
||||
|
||||
public Func<Point, bool>? OpenFlyoutPredicate;
|
||||
public Func<IPopupHostProvider, RawPointerEventArgs, bool>? ClickHideFlyoutPredicate;
|
||||
@ -114,6 +115,7 @@ internal class FlyoutStateHelper : AvaloniaObject
|
||||
}
|
||||
}
|
||||
}
|
||||
FlyoutOpened?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void HandleFlyoutClosed(object? sender, EventArgs e)
|
||||
|
@ -199,6 +199,7 @@ public abstract class InfoPickerInput : TemplatedControl
|
||||
};
|
||||
_flyoutStateHelper.FlyoutAboutToShow += HandleFlyoutAboutToShow;
|
||||
_flyoutStateHelper.FlyoutAboutToClose += HandleFlyoutAboutToClose;
|
||||
_flyoutStateHelper.FlyoutOpened += HandleFlyoutOpened;
|
||||
_flyoutStateHelper.OpenFlyoutPredicate = FlyoutOpenPredicate;
|
||||
_flyoutStateHelper.ClickHideFlyoutPredicate = ClickHideFlyoutPredicate;
|
||||
}
|
||||
@ -232,6 +233,16 @@ public abstract class InfoPickerInput : TemplatedControl
|
||||
{
|
||||
}
|
||||
|
||||
private void HandleFlyoutOpened(object? sender, EventArgs args)
|
||||
{
|
||||
NotifyFlyoutOpened();
|
||||
}
|
||||
|
||||
|
||||
protected virtual void NotifyFlyoutOpened()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual bool ClickHideFlyoutPredicate(IPopupHostProvider hostProvider, RawPointerEventArgs args)
|
||||
{
|
||||
if (hostProvider.PopupHost != args.Root)
|
||||
|
Loading…
Reference in New Issue
Block a user