Hello, I'm making a very simple app with Xamarin forms where I've products with a quantity for each one. Everything is saved in a database:
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }
From a ListView I select my product, and I want to get its informations, Name and Quantity. No problem so far. Then I have a Stepper to increment this quantity, but pressing on it, nothing change from my Quantity.
My XAML:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ProductXAML" Title="Product">
<StackLayout VerticalOptions ="FillAndExpand">
<StackLayout Orientation="Horizontal">
<Label Text="Name :" />
<Label Text="{Binding Name}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Quantity :" />
<Label Text="{Binding Quantity}" />
<Stepper Minimum="0" Increment="1" ValueChanged="OnQuantityChanged" Value="{Binding Quantity}" />
</StackLayout>
</StackLayout>
</ContentPage>
And now the C#
public partial class ProductXAML : ContentPage, INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
StockItem _stockItem;
public ProductXAML (StockItem stockItem)
{
_stockItem = stockItem;
BindingContext = _stockItem;
InitializeComponent ();
}
void OnQuantityChanged(object sender, ValueChangedEventArgs e) {
_stockItem.Quantity = (int)e.NewValue;
Debug.WriteLine (e.NewValue);
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Quantity"));
}
}
Also I've this warning, not sure how to resolve it: `ProductXAML.PropertyChanged hides inherited member Xamarin.Forms.BindableObject.PropertyChanged. Use the new keyword if hiding was intended (CS0108)
Thanks for your help!