任務 5 –將ViewModel 和感應器助手進行整合
1.開啟 SensorViewModel.cs ,並且在私人地區建立一個屬性來暴露光線感應器。
C#
private SensorHelper<AmbientLightSensor, AmbientLightSensor.LuminousIntensity> _sensor;
public SensorHelper<AmbientLightSensor, AmbientLightSensor.LuminousIntensity>
LightSensor
{
get { return _sensor; }
}
2.現在我們來對加速感應器做相同的事。
C#
private SensorHelper<Accelerometer3D, Accelerometer3D.Acceleration3D>
_acceleromaterSensor;
public SensorHelper<Accelerometer3D, Accelerometer3D.Acceleration3D>
AcceleromaterSensor
{
get { return _acceleromaterSensor; }
}
3.我們為SensorViewModel加入一個結構體,用來設定感應器。
C#
public SensorViewModel()
{
_sensor = new SensorHelper<AmbientLightSensor,
AmbientLightSensor.LuminousIntensity>();
_sensor.Initialize();
_acceleromaterSensor = new SensorHelper<Accelerometer3D,
Accelerometer3D.Acceleration3D>();
_acceleromaterSensor.Initialize();
}
4.編譯並測試你的代碼。你應該能夠運行並且與感應器進行整合。