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 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Suresh MRank #171 · 14K reputationPosted Nov 2, 2016, 2:16 AM EDT