我需要呈现一个字符串而不是一个双精度值。
我有一种产生随机电压的方法。该方法作为参数传递,以进一步计算压力。我正在尝试编写代码,因此,如果(随机)电压 = 10,则关联的文本框应显示为“关”。现在,文本框使用方法AveragePressure读取压力值。请找到带有问题的代码。预先谢谢你。
Views / DiagnosticsView.cs:
private void PresBindings()
{
private void PresBindings(Control c,string propertyName,object dataSource,string dataMember)
{
c.DataBindings.Add(propertyName,dataSource,dataMember,true,DataSourceUpdateMode.PropertyChanged);
}
Binding(textBoxVoltage,"Text",viewModel.Gas,nameof(PressureViewModel.Voltage)); //Voltage method in SystemMonitorViewModel.cs
Model / Firmware.cs:
public double GetVoltage()
{
double randVoltage;
lock (lockObject)
{
Random r = new Random();
randVoltage = r.NextDouble()*8.0;
return randVoltage;
}
}
Monitor.cs 字符串p =“-”;
public string Pressure
{
get
{
return p;
}
set
{
if (!string.Equals(value,p))
{
p = value;
Property();
}
}
}
Model / Gauge.cs:
protected Average averagePressure;
public double AveragePressure
{
get
{
Getaverage();
}
}
public override void Read(double voltage,bool trip)
{
double P;
Voltage = voltage;
this.trip= trip;
if ((voltage <= 2 || voltage >= 10))
{
???
}
}
View / MainViewModel.cs
Monitor.Gas.Pressure = sys.VacuumSystem.Gas.AveragePressure.ToString("0.0E-0");
Monitor.Gas.Voltage = sys.VacuumSystem.Gas.Voltage.ToString("0.00");