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

@ -1,4 +1,4 @@
namespace ShoopNCook.Views; /*namespace ShoopNCook.Views;
public partial class CounterView : ContentView public partial class CounterView : ContentView
{ {
@ -48,4 +48,48 @@ public partial class CounterView : ContentView
{ {
Count -= 1; 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