Files
Wino-Mail/Wino.Calendar/Controls/CustomCalendarFlipView.cs
T

83 lines
2.8 KiB
C#
Raw Normal View History

2026-02-13 03:09:13 +01:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
2024-11-10 23:28:25 +01:00
using Windows.UI.Xaml.Controls;
2026-02-13 03:09:13 +01:00
using Wino.Core.Domain.Enums;
2024-11-10 23:28:25 +01:00
2025-05-18 14:06:25 +02: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
2024-11-10 23:28:25 +01:00
{
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";
2024-11-10 23:28:25 +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;
2024-11-10 23:28:25 +01:00
2025-05-18 14:06:25 +02:00
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
2024-11-10 23:28:25 +01:00
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;
2024-11-10 23:28:25 +01:00
2025-05-18 14:06:25 +02:00
// Hide navigation buttons
2026-02-13 03:09:13 +01:00
HideButton(PreviousButtonHorizontal);
HideButton(NextButtonHorizontal);
HideButton(PreviousButtonVertical);
HideButton(NextButtonVertical);
}
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-05-18 14:06:25 +02:00
}
2024-11-10 23:28:25 +01:00
2025-05-18 14:06:25 +02: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-05-18 14:06:25 +02:00
backPeer.Invoke();
}
2024-11-10 23:28:25 +01:00
2025-05-18 14:06:25 +02:00
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-05-18 14:06:25 +02:00
nextPeer.Invoke();
2024-11-10 23:28:25 +01:00
}
}