Files
Wino-Mail/Wino.Mail/MenuFlyouts/AccountSelectorFlyout.cs
Aleh Khantsevich 2ec05ea7cc UWP .NET9 (#555)
* Ground work for NET9 UWP switch.

* Add launch settings for Wino.Mail

* Added new test WAP project

* fix platforms in slnx solution

* ManagePackageVersionsCentrally set default

* Fixing assets and couple issues with the new packaging project.

* Add back markdown

* Fix nuget warnings

* FIx error in WAP about build tools

* Add build.props with default language preview

* Some AOT compilation progress.

* More AOT stuff.

* Remove deprecated protocol auth activation handler.

* Fix remaining protocol handler for google auth.

* Even more AOT

* More more AOT fixes

* Fix a few more AOT warnings

* Fix signature editor AOT

* Fix composer and renderer AOT JSON

* Outlook Sync AOT

* Fixing bundle generation and package signing.

---------

Co-authored-by: Burak Kaan Köse <bkaankose@outlook.com>
2025-02-14 01:43:52 +01:00

61 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Wino.Controls;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.UWP.Controls;
using Wino.Helpers;
namespace Wino.MenuFlyouts
{
public partial class AccountSelectorFlyout : MenuFlyout, IDisposable
{
private readonly IEnumerable<MailAccount> _accounts;
private readonly Func<MailAccount, Task> _onItemSelection;
public AccountSelectorFlyout(IEnumerable<MailAccount> accounts, Func<MailAccount, Task> onItemSelection)
{
_accounts = accounts;
_onItemSelection = onItemSelection;
foreach (var account in _accounts)
{
var pathData = new WinoFontIcon() { Icon = XamlHelpers.GetProviderIcon(account.ProviderType) };
var menuItem = new MenuFlyoutItem() { Tag = account.Address, Icon = pathData, Text = $"{account.Name} ({account.Address})", MinHeight = 55 };
menuItem.Click += AccountClicked;
Items.Add(menuItem);
}
}
public void Dispose()
{
foreach (var menuItem in Items)
{
if (menuItem is MenuFlyoutItem flyoutItem)
{
flyoutItem.Click -= AccountClicked;
}
}
}
private async void AccountClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (sender is MenuFlyoutItem menuItem && menuItem.Tag is string accountAddress)
{
var selectedMenuItem = _accounts.FirstOrDefault(a => a.Address == accountAddress);
if (selectedMenuItem != null)
{
await _onItemSelection(selectedMenuItem);
}
}
Dispose();
Hide();
}
}
}