我正在尝试从 Microsoft Band 获取心率。每当值更改时,它都应该更新。然后我试图在TextBlock
. 我首先创建一个 的实例IBandClient
,并像这样设置它的HeartRate.ReadingChanged
方法:
bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
然后我尝试像这样更新值:
private void HeartRate_ReadingChanged(object sender, Microsoft.Band.Sensors.BandSensorReadingEventArgs<Microsoft.Band.Sensors.IBandHeartRateReading> e)
{
HeartRate = e.SensorReading.HeartRate;
}
HeartRate 是int
这样的集合:
public int HeartRate
{
get { return (int)GetValue(HeartRateProperty); }
set { SetValue(HeartRateProperty, value); }
}
// Using a DependencyProperty as the backing store for HeartRate. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HeartRateProperty =
DependencyProperty.Register("HeartRate", typeof(int), typeof(MainPage), new PropertyMetadata(0));
然后将TextBlock
文本绑定到HeartRate
. 但是,我在尝试设置时不断收到此错误HeartRate
:
应用程序调用了为不同线程编组的接口。(来自 HRESULT 的异常:0x8001010E (RPC_E_WRONG_THREAD))
我的猜测是它正在尝试设置HeartRate
,而它仍然是从之前的调用中设置的。