category selector

This commit is contained in:
gaoyuan
2022-02-28 23:05:21 +08:00
parent 589c7514f2
commit 5b954ac441
28 changed files with 81 additions and 32 deletions

View File

@ -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);
}
}
}

View File

@ -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,