Shell improvements.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using CommunityToolkit.WinUI.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
@@ -8,12 +8,25 @@ using Wino.Core.Domain;
|
||||
|
||||
namespace Wino.Mail.WinUI.Controls;
|
||||
|
||||
public sealed partial class AppModeFooterSwitcherControl : UserControl
|
||||
public sealed partial class AppModeFooterSwitcherControl : Segmented
|
||||
{
|
||||
private const double VerticalItemExtent = 44;
|
||||
private readonly IStatePersistanceService _statePersistenceService;
|
||||
private readonly INavigationService _navigationService;
|
||||
private bool _isUpdatingSelection;
|
||||
|
||||
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
|
||||
nameof(Orientation),
|
||||
typeof(Orientation),
|
||||
typeof(AppModeFooterSwitcherControl),
|
||||
new PropertyMetadata(Orientation.Horizontal, OnOrientationChanged));
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => (Orientation)GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
public AppModeFooterSwitcherControl()
|
||||
{
|
||||
_statePersistenceService = WinoApplication.Current.Services.GetRequiredService<IStatePersistanceService>();
|
||||
@@ -22,9 +35,15 @@ public sealed partial class AppModeFooterSwitcherControl : UserControl
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private static void OnOrientationChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs _)
|
||||
{
|
||||
((AppModeFooterSwitcherControl)dependencyObject).UpdateOrientationState();
|
||||
}
|
||||
|
||||
private void ControlLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_statePersistenceService.StatePropertyChanged += StatePropertyChanged;
|
||||
UpdateOrientationState();
|
||||
UpdateSelection(_statePersistenceService.ApplicationMode);
|
||||
}
|
||||
|
||||
@@ -45,14 +64,14 @@ public sealed partial class AppModeFooterSwitcherControl : UserControl
|
||||
if (_isUpdatingSelection)
|
||||
return;
|
||||
|
||||
if (ModeSegmentedControl.SelectedIndex == 3)
|
||||
if (SelectedIndex == 3)
|
||||
{
|
||||
_navigationService.Navigate(WinoPage.SettingsPage);
|
||||
UpdateSelection(_statePersistenceService.ApplicationMode);
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedMode = ModeSegmentedControl.SelectedIndex switch
|
||||
var selectedMode = SelectedIndex switch
|
||||
{
|
||||
1 => WinoApplicationMode.Calendar,
|
||||
2 => WinoApplicationMode.Contacts,
|
||||
@@ -68,7 +87,7 @@ public sealed partial class AppModeFooterSwitcherControl : UserControl
|
||||
private void UpdateSelection(WinoApplicationMode mode)
|
||||
{
|
||||
_isUpdatingSelection = true;
|
||||
ModeSegmentedControl.SelectedIndex = mode switch
|
||||
SelectedIndex = mode switch
|
||||
{
|
||||
WinoApplicationMode.Calendar => 1,
|
||||
WinoApplicationMode.Contacts => 2,
|
||||
@@ -76,4 +95,24 @@ public sealed partial class AppModeFooterSwitcherControl : UserControl
|
||||
};
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
|
||||
private void UpdateOrientationState()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is not SegmentedItem segmentedItem)
|
||||
continue;
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
{
|
||||
segmentedItem.Width = VerticalItemExtent;
|
||||
segmentedItem.Height = VerticalItemExtent;
|
||||
}
|
||||
else
|
||||
{
|
||||
segmentedItem.ClearValue(WidthProperty);
|
||||
segmentedItem.ClearValue(HeightProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user