有没有办法使滑块动态更改其价值



我有一些从GPS收集的数据,在计算当前位置和这些GPS数据之间的距离之后,我希望滑块在接近这一点时自动移动。

,但是问题是,当我放一段时间循环以更新距离值时,我会在UI中得到一个错误。因此,我删除了循环,但无法实时显示距离的新值。

首先,我计算了路线的第一个点和最后一个点之间的距离,然后将此值作为滑块的最大值。必须动态更改的滑块的值是距起点点的距离。

private async  void Prog()
        {
            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;
            var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(1));
            double startpoint = distance_on_geoid(position.Latitude,position.Longitude,JSONData.GetGlcLatitude1()[0],JSONData.GetGlcLongitude1()[0]);
            double endpoint = distance_on_geoid(position.Latitude, position.Longitude, JSONData.GetGlcLatitude1()[JSONData.GetGlcLatitude1().Count-1], JSONData.GetGlcLongitude1()[JSONData.GetGlcLongitude1().Count-1]);
            double alertDistance = distance_on_geoid(JSONData.GetGlcLatitude1()[0], JSONData.GetGlcLongitude1()[0], JSONData.GetGlcLatitude1()[JSONData.GetGlcLatitude1().Count - 1], JSONData.GetGlcLongitude1()[JSONData.GetGlcLongitude1().Count - 1]);
            slider.Maximum = alertDistance;
            double startpoint_ = Convert.ToDouble(String.Format("{0:0.00}", startpoint));
            test.Text = startpoint_.ToString();
                if (startpoint_>=0.01)
                {
                    slider.IsVisible = true;
                    slider.Value = alertDistance - endpoint;
            }
                else
                {
                    slider.IsVisible = false;
                }
        }

(jsondata ...是我的路线值(

我希望当我接近终点时,滑块会自动移动。只有在区域中IM时才能看到滑块,否则必须是看不见的。

我现在看到了问题,因为您正在从背景线程上对UI进行更改,例如这样做:

Device.BeginInvokeOnMainThread (() => 
{
 slider.IsVisible = true;
 slider.Value = alertDistance - endpoint;
}

始终看到您在主线上的UI上进行更改,而不是某些背景线程,即使用async-await作为Eg

相关内容

最新更新