0
我正在使用Windows Phone應用程序和我的應用程序從Web服務獲取數據,有時連接不好時會出現錯誤並且不顯示數據,因此我在應用程序中添加了一個刷新按鈕,在那些應用程序中,我從mainviewmodel調用loaddata,但沒有發生,有什麼問題?刷新Xaml UI數據綁定
MainViewModel mv = new MainViewModel();
private void refreshButton_Click(object sender, EventArgs e)
{
mv.LoadData();
}
,這裏是loadData()在我的mainviewmodel.cs
public void LoadData()
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition position =
await geolocator.GetGeopositionAsync(
TimeSpan.FromMinutes(1),
TimeSpan.FromSeconds(30));
center = new GeoCoordinate(
position.Coordinate.Latitude,
position.Coordinate.Longitude);
latitude = position.Coordinate.Latitude;
longitude = position.Coordinate.Longitude;
UpdateTransport();
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disable in phone settings.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.IsDataLoaded = true;
}