Counter view binding
continuous-integration/drone/push Build is passing Details

master
Leo TUAILLON 2 years ago
parent 7777304ef3
commit aaad6748cd

@ -3,6 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.CounterView"
x:Name="Counter">
<ContentView.BindingContext>
<x:Reference Name="Counter"/>
</ContentView.BindingContext>
<Grid
ColumnDefinitions="*, Auto, *">
@ -23,15 +26,13 @@
Spacing="3"
Margin="10, 0, 10, 0">
<Label
x:Name="CountLabel"
Text="{Binding Count, Source={x:Reference Counter}}"
Text="{Binding Count}"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
<Label
x:Name="CounterLabel"
Text="{Binding CounterText, Source={x:Reference Counter}}"
Text="{Binding CounterText}"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>

@ -1,4 +1,4 @@
namespace ShoopNCook.Views;
/*namespace ShoopNCook.Views;
public partial class CounterView : ContentView
{
@ -48,4 +48,48 @@ public partial class CounterView : ContentView
{
Count -= 1;
}
}
}*/
namespace ShoopNCook.Views;
public partial class CounterView : ContentView
{
public static readonly BindableProperty CountProperty =
BindableProperty.Create(nameof(Count), typeof(uint), typeof(CounterView), default(uint) + 1);
public static readonly BindableProperty CounterTextProperty =
BindableProperty.Create(nameof(CounterText), typeof(string), typeof(CounterView), default(string));
public CounterView()
{
InitializeComponent();
}
public uint Count
{
get => (uint)GetValue(CountProperty);
set
{
SetValue(CountProperty, value <= 1 ? 1 : uint.Parse(value.ToString()));
}
}
public string CounterText
{
get => (string)GetValue(CounterTextProperty);
set
{
SetValue(CounterTextProperty, value);
}
}
private void OnPlus(object o, EventArgs e)
{
Count += 1;
}
private void OnMinus(object o, EventArgs e)
{
Count -= 1;
}
}

Loading…
Cancel
Save