您必须存储原始值。我正在使用以下模式。
假设你有一个像这样
public class Model
{
public int ActualReading {get; set;}
}
一个模型,这样的视图模型(我删除了更好的阅读了INotifyPropertyChanged
部分)
public class ViewModel
{
private readonly Model MyModel;
private int _actualReading;
public int ActualReading
{
get { return _actualReading; }
set { _actualReading = value; }
}
public ViewModel(Model model)
{
MyModel = model;
ActualReading = model.ActualReading;
}
public Model GetModel()
{
MyModel.ActualReading = ActualReading;
return MyModel;
}
}
当您创建ViewModel
情况下,你用初始化相应的Model
实例。当你已经实现这个,你可以像这样简单的方式添加你的支票。
private int _actualReading;
public int ActualReading
{
get { return _actualReading; }
set
{
if (value >= MyModel.ActualReading)
{
_actualReading = value;
}
else
{
UserDialogs.Instance.Alert("Meter readings should not be smaller than previous value.", "Error", "Ok");
}
}
}
将它保存在第一集中的变量? –
从当是你的“第一次”的价值在其上的测量都应该是相对于一个上?在保存数据后,您是否允许更改为原始高于第一个值但低于实际值? – Icepickle
是的,我会允许的。就像这样,我的数据网格有很多行。每行都有一个来自数据库的具有原始值的字段。原始值可以编辑,但编辑的值必须等于或大于原始值。假设原来是10.现在我编辑它到30,然后我移动到下一行。如果我来之前编辑的行,它会显示30.我不能将值30编辑以较小的数字比30,因为现在30已经取代10该行原来的值。 – batwing