balance binding

This commit is contained in:
2022-02-26 17:29:12 +08:00
parent 4d69bea70b
commit 283acf7d35
6 changed files with 59 additions and 32 deletions

View File

@ -19,7 +19,7 @@ namespace Billing.UI
return obj;
}
public static View HorizontalOptions(this View view, LayoutOptions options)
public static T HorizontalOptions<T>(this T view, LayoutOptions options) where T : View
{
if (view != null)
{
@ -28,7 +28,7 @@ namespace Billing.UI
return view;
}
public static View VerticalOptions(this View view, LayoutOptions options)
public static T VerticalOptions<T>(this T view, LayoutOptions options) where T : View
{
if (view != null)
{
@ -37,41 +37,41 @@ namespace Billing.UI
return view;
}
public static View DynamicResource(this View view, BindableProperty property, string key)
public static T Margin<T>(this T view, Thickness margin) where T : View
{
view.Margin = margin;
return view;
}
public static T DynamicResource<T>(this T view, BindableProperty property, string key) where T : Element
{
view.SetDynamicResource(property, key);
return view;
}
public static View GridColumn(this View view, int column)
public static T GridColumn<T>(this T view, int column) where T : BindableObject
{
Grid.SetColumn(view, column);
return view;
}
public static View GridRow(this View view, int row)
public static T GridRow<T>(this T view, int row) where T : BindableObject
{
Grid.SetRow(view, row);
return view;
}
public static View GridColumnSpan(this View view, int columnSpan)
public static T GridColumnSpan<T>(this T view, int columnSpan) where T : BindableObject
{
Grid.SetColumnSpan(view, columnSpan);
return view;
}
public static View GridRowSpan(this View view, int rowSpan)
public static T GridRowSpan<T>(this T view, int rowSpan) where T : BindableObject
{
Grid.SetRowSpan(view, rowSpan);
return view;
}
public static View Margin(this View view, Thickness margin)
{
view.Margin = margin;
return view;
}
}
public class Tap : IDisposable

View File

@ -1,4 +1,5 @@
using Billing.Themes;
using System;
using Xamarin.Forms;
namespace Billing.UI
@ -269,19 +270,34 @@ namespace Billing.UI
set => SetValue(PlaceholderProperty, value);
}
protected override View Content => new OptionEntry
public event EventHandler<FocusEventArgs> Unfocused;
protected override View Content
{
HorizontalOptions = LayoutOptions.Fill,
HorizontalTextAlignment = TextAlignment.End,
VerticalOptions = LayoutOptions.Center,
ReturnType = ReturnType.Next
get
{
var content = new OptionEntry
{
HorizontalOptions = LayoutOptions.Fill,
HorizontalTextAlignment = TextAlignment.End,
VerticalOptions = LayoutOptions.Center,
ReturnType = ReturnType.Next
}
.Binding(Entry.TextProperty, nameof(Text), BindingMode.TwoWay)
.Binding(InputView.KeyboardProperty, nameof(Keyboard))
.Binding(Entry.PlaceholderProperty, nameof(Placeholder))
.DynamicResource(Entry.TextColorProperty, BaseTheme.TextColor)
.DynamicResource(Entry.PlaceholderColorProperty, BaseTheme.SecondaryTextColor)
.DynamicResource(VisualElement.BackgroundColorProperty, BaseTheme.OptionTintColor);
content.Unfocused += Content_Unfocused;
return content;
}
}
private void Content_Unfocused(object sender, FocusEventArgs e)
{
Unfocused?.Invoke(sender, e);
}
.Binding(Entry.TextProperty, nameof(Text), BindingMode.TwoWay)
.Binding(InputView.KeyboardProperty, nameof(Keyboard))
.Binding(Entry.PlaceholderProperty, nameof(Placeholder))
.DynamicResource(Entry.TextColorProperty, BaseTheme.TextColor)
.DynamicResource(Entry.PlaceholderColorProperty, BaseTheme.SecondaryTextColor)
.DynamicResource(VisualElement.BackgroundColorProperty, BaseTheme.OptionTintColor);
}
public class OptionEditorCell : OptionVerticalCell