icon select
This commit is contained in:
80
Billing.Shared/Views/IconSelectPage.xaml.cs
Normal file
80
Billing.Shared/Views/IconSelectPage.xaml.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using Billing.Models;
|
||||
using Billing.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Billing.Views
|
||||
{
|
||||
public partial class IconSelectPage : BillingPage
|
||||
{
|
||||
public static readonly BindableProperty IconsSourceProperty = BindableProperty.Create(nameof(IconsSource), typeof(IList<BillingIcon>), typeof(IconSelectPage));
|
||||
|
||||
public IList<BillingIcon> IconsSource
|
||||
{
|
||||
get => (IList<BillingIcon>)GetValue(IconsSourceProperty);
|
||||
set => SetValue(IconsSourceProperty, value);
|
||||
}
|
||||
|
||||
public Command IconCheck { get; }
|
||||
|
||||
public event EventHandler<string> IconChecked;
|
||||
|
||||
private string iconChecked;
|
||||
|
||||
public IconSelectPage(string icon)
|
||||
{
|
||||
iconChecked = icon;
|
||||
IconCheck = new Command(OnIconCheck);
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
InitIcons();
|
||||
}
|
||||
|
||||
private void InitIcons()
|
||||
{
|
||||
var source = new List<BillingIcon>
|
||||
{
|
||||
new() { Icon = BaseModel.ICON_DEFAULT },
|
||||
new() { Icon = "wallet" }
|
||||
};
|
||||
source.AddRange(IconConverter.IconPreset.Select(icon => new BillingIcon { Icon = $"#brand#{icon.Key}" }));
|
||||
foreach (var icon in source)
|
||||
{
|
||||
if (icon.Icon == iconChecked)
|
||||
{
|
||||
icon.IsChecked = true;
|
||||
}
|
||||
}
|
||||
IconsSource = source;
|
||||
}
|
||||
|
||||
private async void OnIconCheck(object o)
|
||||
{
|
||||
if (o is string icon)
|
||||
{
|
||||
foreach (var ic in IconsSource)
|
||||
{
|
||||
ic.IsChecked = ic.Icon == icon;
|
||||
}
|
||||
iconChecked = icon;
|
||||
IconChecked?.Invoke(this, icon);
|
||||
await Navigation.PopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BillingIcon : BindableObject
|
||||
{
|
||||
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(BillingIcon));
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get => (bool)GetValue(IsCheckedProperty);
|
||||
set => SetValue(IsCheckedProperty, value);
|
||||
}
|
||||
public string Icon { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user