category selector
This commit is contained in:
		@@ -1,44 +1,63 @@
 | 
			
		||||
using Billing.Themes;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Xamarin.Forms;
 | 
			
		||||
 | 
			
		||||
namespace Billing.UI
 | 
			
		||||
{
 | 
			
		||||
    public class ItemSelectPage : ContentPage
 | 
			
		||||
    public class ItemSelectPage<T> : ContentPage
 | 
			
		||||
    {
 | 
			
		||||
        public ItemSelectPage(IList source)
 | 
			
		||||
        public event EventHandler<T> ItemTapped;
 | 
			
		||||
 | 
			
		||||
        public ItemSelectPage(IEnumerable<T> source)
 | 
			
		||||
        {
 | 
			
		||||
            Content = new ListView
 | 
			
		||||
            var content = new ListView
 | 
			
		||||
            {
 | 
			
		||||
                ItemsSource = source,
 | 
			
		||||
                ItemTemplate = new DataTemplate(() => new StackLayout
 | 
			
		||||
                ItemTemplate = new DataTemplate(() => new ViewCell
 | 
			
		||||
                {
 | 
			
		||||
                    Orientation = StackOrientation.Horizontal,
 | 
			
		||||
                    Padding = new Thickness(20, 0),
 | 
			
		||||
                    Spacing = 10,
 | 
			
		||||
                    Children =
 | 
			
		||||
                    View = new StackLayout
 | 
			
		||||
                    {
 | 
			
		||||
                        new Image
 | 
			
		||||
                        Orientation = StackOrientation.Horizontal,
 | 
			
		||||
                        Padding = new Thickness(20, 0),
 | 
			
		||||
                        Spacing = 10,
 | 
			
		||||
                        Children =
 | 
			
		||||
                        {
 | 
			
		||||
                            WidthRequest = 22,
 | 
			
		||||
                            HeightRequest = 22,
 | 
			
		||||
                            Aspect = Aspect.AspectFit,
 | 
			
		||||
                            VerticalOptions = LayoutOptions.Center
 | 
			
		||||
                        }
 | 
			
		||||
                        .Binding(Image.SourceProperty, "Icon"),
 | 
			
		||||
                            new Image
 | 
			
		||||
                            {
 | 
			
		||||
                                WidthRequest = 22,
 | 
			
		||||
                                HeightRequest = 22,
 | 
			
		||||
                                Aspect = Aspect.AspectFit,
 | 
			
		||||
                                VerticalOptions = LayoutOptions.Center
 | 
			
		||||
                            }
 | 
			
		||||
                            .Binding(Image.SourceProperty, "Icon"),
 | 
			
		||||
 | 
			
		||||
                        new Label
 | 
			
		||||
                        {
 | 
			
		||||
                            VerticalOptions = LayoutOptions.Center,
 | 
			
		||||
                            LineBreakMode = LineBreakMode.TailTruncation
 | 
			
		||||
                            new Label
 | 
			
		||||
                            {
 | 
			
		||||
                                VerticalOptions = LayoutOptions.Center,
 | 
			
		||||
                                LineBreakMode = LineBreakMode.TailTruncation
 | 
			
		||||
                            }
 | 
			
		||||
                            .Binding(Label.TextProperty, "Name")
 | 
			
		||||
                            .DynamicResource(Label.TextColorProperty, BaseTheme.TextColor)
 | 
			
		||||
                        }
 | 
			
		||||
                        .Binding(Label.TextProperty, "Name")
 | 
			
		||||
                        .DynamicResource(Label.TextColorProperty, BaseTheme.TextColor)
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
            .DynamicResource(BackgroundColorProperty, BaseTheme.WindowBackgroundColor);
 | 
			
		||||
 | 
			
		||||
            // events
 | 
			
		||||
            content.ItemTapped += List_ItemTapped;
 | 
			
		||||
 | 
			
		||||
            Content = content;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void List_ItemTapped(object sender, ItemTappedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            if (e.Item is T t)
 | 
			
		||||
            {
 | 
			
		||||
                ItemTapped?.Invoke(this, t);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,7 @@ namespace Billing.UI
 | 
			
		||||
                },
 | 
			
		||||
                Children =
 | 
			
		||||
                {
 | 
			
		||||
                    new Image
 | 
			
		||||
                    new TintImage
 | 
			
		||||
                    {
 | 
			
		||||
                        WidthRequest = 20,
 | 
			
		||||
                        HeightRequest = 20,
 | 
			
		||||
@@ -93,7 +93,7 @@ namespace Billing.UI
 | 
			
		||||
                },
 | 
			
		||||
                Children =
 | 
			
		||||
                {
 | 
			
		||||
                    new Image
 | 
			
		||||
                    new TintImage
 | 
			
		||||
                    {
 | 
			
		||||
                        WidthRequest = 20,
 | 
			
		||||
                        HeightRequest = 20,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user