add account
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Xamarin.Forms;
|
||||
@ -24,17 +25,36 @@ namespace Billing.UI
|
||||
|
||||
public class MoneyConverter : IValueConverter
|
||||
{
|
||||
public bool MarkVisible { get; set; } = true;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is decimal d)
|
||||
{
|
||||
return "¥ " + d.ToString("n2", CultureInfo.InvariantCulture);
|
||||
var number = d.ToString("n2");
|
||||
if (MarkVisible)
|
||||
{
|
||||
return "¥ " + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string s)
|
||||
{
|
||||
if (s.StartsWith("¥ "))
|
||||
{
|
||||
s = s[2..];
|
||||
}
|
||||
if (decimal.TryParse(s, out decimal d))
|
||||
{
|
||||
return d;
|
||||
}
|
||||
return 0m;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -51,4 +71,28 @@ namespace Billing.UI
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class AccountCategoryConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is AccountCategory category)
|
||||
{
|
||||
return category switch
|
||||
{
|
||||
AccountCategory.Cash => Resource.Cash,
|
||||
AccountCategory.CreditCard => Resource.CreditCard,
|
||||
AccountCategory.DebitCard => Resource.DebitCard,
|
||||
AccountCategory.ElecAccount => Resource.ElecAccount,
|
||||
_ => category.ToString()
|
||||
};
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,24 @@ namespace Billing.UI
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static View HorizontalOptions(this View view, LayoutOptions options)
|
||||
{
|
||||
if (view != null)
|
||||
{
|
||||
view.HorizontalOptions = options;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public static View VerticalOptions(this View view, LayoutOptions options)
|
||||
{
|
||||
if (view != null)
|
||||
{
|
||||
view.VerticalOptions = options;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public static View DynamicResource(this View view, BindableProperty property, string key)
|
||||
{
|
||||
view.SetDynamicResource(property, key);
|
||||
|
@ -186,6 +186,49 @@ namespace Billing.UI
|
||||
};
|
||||
}
|
||||
|
||||
public class OptionImageCell : OptionSelectCell
|
||||
{
|
||||
public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(OptionImageCell));
|
||||
|
||||
[TypeConverter(typeof(ImageSourceConverter))]
|
||||
public ImageSource ImageSource
|
||||
{
|
||||
get => (ImageSource)GetValue(ImageSourceProperty);
|
||||
set => SetValue(ImageSourceProperty, value);
|
||||
}
|
||||
|
||||
protected override View Content => new StackLayout
|
||||
{
|
||||
Orientation = StackOrientation.Horizontal,
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
Children =
|
||||
{
|
||||
new Image
|
||||
{
|
||||
HeightRequest = 20,
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(6, 0)
|
||||
}
|
||||
.Binding(Image.SourceProperty, nameof(ImageSource)),
|
||||
|
||||
new TintImage
|
||||
{
|
||||
HeightRequest = 20,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(6, 0),
|
||||
Source = "right.png"
|
||||
}
|
||||
},
|
||||
GestureRecognizers =
|
||||
{
|
||||
new TapGestureRecognizer()
|
||||
.Binding(TapGestureRecognizer.CommandProperty, nameof(Command))
|
||||
.Binding(TapGestureRecognizer.CommandParameterProperty, nameof(CommandParameter))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class OptionSwitchCell : OptionCell
|
||||
{
|
||||
public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(OptionSwitchCell));
|
||||
|
Reference in New Issue
Block a user