Calendar stuff.

This commit is contained in:
Burak Kaan Köse
2026-02-13 03:09:13 +01:00
parent e936c431a2
commit 884f000058
22 changed files with 470 additions and 115 deletions
@@ -1,7 +1,8 @@
using System.Linq;
using System.Linq;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using Wino.Core.Domain.Enums;
using Wino.Mail.WinUI.Controls.CalendarFlipView;
namespace Wino.Calendar.Controls;
@@ -11,27 +12,56 @@ namespace Wino.Calendar.Controls;
/// </summary>
public partial class CustomCalendarFlipView : FlipView
{
private const string PART_PreviousButton = "PreviousButtonHorizontal";
private const string PART_NextButton = "NextButtonHorizontal";
private const string PART_PreviousButtonHorizontal = "PreviousButtonHorizontal";
private const string PART_NextButtonHorizontal = "NextButtonHorizontal";
private const string PART_PreviousButtonVertical = "PreviousButtonVertical";
private const string PART_NextButtonVertical = "NextButtonVertical";
private Button? PreviousButton;
private Button? NextButton;
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;
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
PreviousButton = (Button)GetTemplateChild(PART_PreviousButton);
NextButton = (Button)GetTemplateChild(PART_NextButton);
PreviousButtonHorizontal = GetTemplateChild(PART_PreviousButtonHorizontal) as Button;
NextButtonHorizontal = GetTemplateChild(PART_NextButtonHorizontal) as Button;
PreviousButtonVertical = GetTemplateChild(PART_PreviousButtonVertical) as Button;
NextButtonVertical = GetTemplateChild(PART_NextButtonVertical) as Button;
// Hide navigation buttons
PreviousButton.Opacity = NextButton.Opacity = 0;
PreviousButton.IsHitTestVisible = NextButton.IsHitTestVisible = false;
HideButton(PreviousButtonHorizontal);
HideButton(NextButtonHorizontal);
HideButton(PreviousButtonVertical);
HideButton(NextButtonVertical);
this.SelectionChanged += FlipViewSelectionChanged;
SelectionChanged += FlipViewSelectionChanged;
}
private void FlipViewSelectionChanged(object sender, SelectionChangedEventArgs e) => OnSelectedItemChanged(e.RemovedItems.FirstOrDefault(), e.AddedItems.FirstOrDefault());
private static void HideButton(Button? button)
{
if (button == null) return;
button.Opacity = 0;
button.IsHitTestVisible = false;
}
private void FlipViewSelectionChanged(object sender, SelectionChangedEventArgs e)
=> OnSelectedItemChanged(e.RemovedItems.FirstOrDefault(), e.AddedItems.FirstOrDefault());
protected virtual void OnSelectedItemChanged(object oldValue, object newValue) { }
@@ -47,13 +77,25 @@ public partial class CustomCalendarFlipView : FlipView
public void GoPreviousFlip()
{
var backPeer = new ButtonAutomationPeer(PreviousButton);
var previousButton = DisplayType == CalendarDisplayType.Month
? PreviousButtonVertical ?? PreviousButtonHorizontal
: PreviousButtonHorizontal ?? PreviousButtonVertical;
if (previousButton == null) return;
var backPeer = new ButtonAutomationPeer(previousButton);
backPeer.Invoke();
}
public void GoNextFlip()
{
var nextPeer = new ButtonAutomationPeer(NextButton);
var nextButton = DisplayType == CalendarDisplayType.Month
? NextButtonVertical ?? NextButtonHorizontal
: NextButtonHorizontal ?? NextButtonVertical;
if (nextButton == null) return;
var nextPeer = new ButtonAutomationPeer(nextButton);
nextPeer.Invoke();
}
}