Files
Wino-Mail/Wino.Mail/Controls/AccountNavigationItem.cs
T

63 lines
2.3 KiB
C#
Raw Normal View History

using System.Numerics;
2024-04-18 01:44:37 +02:00
using Microsoft.UI.Xaml.Controls;
using Windows.UI.Xaml;
using Wino.Core.Domain.Interfaces;
2024-11-10 23:28:25 +01:00
using Wino.Core.UWP.Controls;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
namespace Wino.Controls;
public partial class AccountNavigationItem : WinoNavigationViewItem
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
public static readonly DependencyProperty IsActiveAccountProperty = DependencyProperty.Register(nameof(IsActiveAccount), typeof(bool), typeof(AccountNavigationItem), new PropertyMetadata(false, new PropertyChangedCallback(OnIsActiveAccountChanged)));
public static readonly DependencyProperty BindingDataProperty = DependencyProperty.Register(nameof(BindingData), typeof(IAccountMenuItem), typeof(AccountNavigationItem), new PropertyMetadata(null));
2025-02-16 11:54:23 +01:00
public bool IsActiveAccount
{
get { return (bool)GetValue(IsActiveAccountProperty); }
set { SetValue(IsActiveAccountProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public IAccountMenuItem BindingData
{
get { return (IAccountMenuItem)GetValue(BindingDataProperty); }
set { SetValue(BindingDataProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private const string PART_NavigationViewItemMenuItemsHost = "NavigationViewItemMenuItemsHost";
private const string PART_SelectionIndicator = "CustomSelectionIndicator";
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private ItemsRepeater _itemsRepeater;
private Windows.UI.Xaml.Shapes.Rectangle _selectionIndicator;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public AccountNavigationItem()
{
DefaultStyleKey = typeof(AccountNavigationItem);
}
2025-02-16 11:54:23 +01:00
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
_itemsRepeater = GetTemplateChild(PART_NavigationViewItemMenuItemsHost) as ItemsRepeater;
_selectionIndicator = GetTemplateChild(PART_SelectionIndicator) as Windows.UI.Xaml.Shapes.Rectangle;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
UpdateSelectionBorder();
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private static void OnIsActiveAccountChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is AccountNavigationItem control)
control.UpdateSelectionBorder();
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void UpdateSelectionBorder()
{
if (_selectionIndicator == null) return;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
_selectionIndicator.Scale = IsActiveAccount ? new Vector3(1, 1, 1) : new Vector3(0, 0, 0);
_selectionIndicator.Visibility = IsActiveAccount ? Visibility.Visible : Visibility.Collapsed;
2024-04-18 01:44:37 +02:00
}
}