2026-02-13 03:09:13 +01:00
|
|
|
using System.Linq;
|
2025-12-30 10:02:24 +01:00
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Microsoft.UI.Xaml.Automation.Peers;
|
2025-12-26 20:46:48 +01:00
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2026-02-13 03:09:13 +01:00
|
|
|
using Wino.Core.Domain.Enums;
|
2025-12-30 10:02:24 +01:00
|
|
|
using Wino.Mail.WinUI.Controls.CalendarFlipView;
|
2025-12-26 20:46:48 +01:00
|
|
|
|
|
|
|
|
namespace Wino.Calendar.Controls;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// FlipView that hides the navigation buttons and exposes methods to navigate to the next and previous items with animations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class CustomCalendarFlipView : FlipView
|
|
|
|
|
{
|
2026-02-13 03:09:13 +01:00
|
|
|
private const string PART_PreviousButtonHorizontal = "PreviousButtonHorizontal";
|
|
|
|
|
private const string PART_NextButtonHorizontal = "NextButtonHorizontal";
|
|
|
|
|
private const string PART_PreviousButtonVertical = "PreviousButtonVertical";
|
|
|
|
|
private const string PART_NextButtonVertical = "NextButtonVertical";
|
2025-12-26 20:46:48 +01:00
|
|
|
|
2026-02-13 03:09:13 +01:00
|
|
|
public static readonly DependencyProperty DisplayTypeProperty = DependencyProperty.Register(
|
|
|
|
|
nameof(DisplayType),
|
|
|
|
|
typeof(CalendarDisplayType),
|
|
|
|
|
typeof(CustomCalendarFlipView),
|
|
|
|
|
new PropertyMetadata(CalendarDisplayType.Week));
|
|
|
|
|
|
|
|
|
|
public CalendarDisplayType DisplayType
|
|
|
|
|
{
|
|
|
|
|
get => (CalendarDisplayType)GetValue(DisplayTypeProperty);
|
|
|
|
|
set => SetValue(DisplayTypeProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Button? PreviousButtonHorizontal;
|
|
|
|
|
private Button? NextButtonHorizontal;
|
|
|
|
|
private Button? PreviousButtonVertical;
|
|
|
|
|
private Button? NextButtonVertical;
|
2025-12-26 20:46:48 +01:00
|
|
|
|
|
|
|
|
protected override void OnApplyTemplate()
|
|
|
|
|
{
|
|
|
|
|
base.OnApplyTemplate();
|
|
|
|
|
|
2026-02-13 03:09:13 +01:00
|
|
|
PreviousButtonHorizontal = GetTemplateChild(PART_PreviousButtonHorizontal) as Button;
|
|
|
|
|
NextButtonHorizontal = GetTemplateChild(PART_NextButtonHorizontal) as Button;
|
|
|
|
|
PreviousButtonVertical = GetTemplateChild(PART_PreviousButtonVertical) as Button;
|
|
|
|
|
NextButtonVertical = GetTemplateChild(PART_NextButtonVertical) as Button;
|
2025-12-26 20:46:48 +01:00
|
|
|
|
|
|
|
|
// Hide navigation buttons
|
2026-02-13 03:09:13 +01:00
|
|
|
HideButton(PreviousButtonHorizontal);
|
|
|
|
|
HideButton(NextButtonHorizontal);
|
|
|
|
|
HideButton(PreviousButtonVertical);
|
|
|
|
|
HideButton(NextButtonVertical);
|
|
|
|
|
|
|
|
|
|
SelectionChanged += FlipViewSelectionChanged;
|
|
|
|
|
}
|
2025-12-30 10:02:24 +01:00
|
|
|
|
2026-02-13 03:09:13 +01:00
|
|
|
private static void HideButton(Button? button)
|
|
|
|
|
{
|
|
|
|
|
if (button == null) return;
|
|
|
|
|
|
|
|
|
|
button.Opacity = 0;
|
|
|
|
|
button.IsHitTestVisible = false;
|
2025-12-30 10:02:24 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 03:09:13 +01:00
|
|
|
private void FlipViewSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
=> OnSelectedItemChanged(e.RemovedItems.FirstOrDefault(), e.AddedItems.FirstOrDefault());
|
2025-12-30 10:02:24 +01:00
|
|
|
|
2026-02-27 20:12:43 +01:00
|
|
|
protected virtual void OnSelectedItemChanged(object? oldValue, object? newValue) { }
|
2025-12-30 10:02:24 +01:00
|
|
|
|
|
|
|
|
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
|
|
|
|
|
{
|
|
|
|
|
base.PrepareContainerForItemOverride(element, item);
|
|
|
|
|
OnContainerPrepared(element, item);
|
2025-12-26 20:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-30 10:02:24 +01:00
|
|
|
protected virtual void OnContainerPrepared(DependencyObject element, object item) { }
|
|
|
|
|
|
|
|
|
|
protected override DependencyObject GetContainerForItemOverride() => new WinoCalendarFlyoutItem();
|
|
|
|
|
|
2025-12-26 20:46:48 +01:00
|
|
|
public void GoPreviousFlip()
|
|
|
|
|
{
|
2026-02-13 03:09:13 +01:00
|
|
|
var previousButton = DisplayType == CalendarDisplayType.Month
|
|
|
|
|
? PreviousButtonVertical ?? PreviousButtonHorizontal
|
|
|
|
|
: PreviousButtonHorizontal ?? PreviousButtonVertical;
|
|
|
|
|
|
|
|
|
|
if (previousButton == null) return;
|
|
|
|
|
|
|
|
|
|
var backPeer = new ButtonAutomationPeer(previousButton);
|
2025-12-26 20:46:48 +01:00
|
|
|
backPeer.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GoNextFlip()
|
|
|
|
|
{
|
2026-02-13 03:09:13 +01:00
|
|
|
var nextButton = DisplayType == CalendarDisplayType.Month
|
|
|
|
|
? NextButtonVertical ?? NextButtonHorizontal
|
|
|
|
|
: NextButtonHorizontal ?? NextButtonVertical;
|
|
|
|
|
|
|
|
|
|
if (nextButton == null) return;
|
|
|
|
|
|
|
|
|
|
var nextPeer = new ButtonAutomationPeer(nextButton);
|
2025-12-26 20:46:48 +01:00
|
|
|
nextPeer.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|