Model: Coffee.cs
public class Coffee:BindableBase
{
private int coffeeId;
private string coffeeName;
public int CoffeeId
{
get
{
return coffeeId;
}
set
{
coffeeId = value;
RaisePropertyChanged("CoffeeId");
}
}
public string CoffeeName
{
get
{
return coffeeName;
}
set
{
coffeeName = value;
RaisePropertyChanged("CoffeeName");
}
}
}
View: CoffeeAdd.xaml
View Model:CoffeeAddViewModel
public class CoffeeAddViewModel:BindableBase
{
private ICoffeeDataService coffeedataservice;
public CoffeeAddViewModel(ICoffeeDataService dataservice)
{
coffeedataservice = dataservice;
LoadCommand();
}
private int _coffeeId;
private string _coffeeName;
public int CoffeeId
{
get
{
return _coffeeId;
}
set
{
_coffeeId = value;
RaisePropertyChanged("CoffeeId");
}
}
public string CoffeeName
{
get
{
return _coffeeName;
}
set
{
_coffeeName = value;
RaisePropertyChanged("CoffeeName");
}
}
public ICommand AddCommand { get; set; }
private void LoadCommand()
{
AddCommand = new CustomCommand(add, canadd);
}
private async void add(object obj)
{
coffeedataservice.AddCoffee(new Model.Coffee { CoffeeId = _coffeeId, CoffeeName = _coffeeName });
var dialog = new MessageDialog("Successfully Added");
await dialog.ShowAsync();
}
private bool canadd(object obj)
{
return true;
}
}
I want to add new coffee details,when i add using Addcommand (custom command) but when add new details is null, so how i avoid this issue?
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suresh MPosted Nov 2, 2016, 6:16 AM