I was developing an app in WinRT, I had requirement of passing property values, which are set in one class, to another class, but I am not able to get them. My below code will explain you my problem. Please note I have tested this in simulator and added the capability for location in manifest. I have set location in simulator.
MainPage.xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="MyTextBlock"/>
</Grid>
MainPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MyClass objMyClass = new MyClass();
MyTextBlock.Text = objMyClass.Lat.ToString() + ", " + objMyClass.Long.ToString();
}
MyClass.cs
public class MyClass
{
public double Lat { get; set; }
public double Long { get; set; }
public MyClass()
{
FindLatLong();
}
public async void FindLatLong()
{
Geolocator geolocator = new Geolocator();
var pos = await geolocator.GetGeopositionAsync();
Lat = pos.Coordinate.Latitude;
Long = pos.Coordinate.Longitude;
}
}
I am getting output “0,0”
Finally got my answer from MSDN forum.