I have one method who get data from API:
async Task WaterDataForecast()
{
WaterBindingData waterData = await _restServiceData.GetWaterDataForecast(GenerateRequestUri(Constants.EndPoint), GenerateRequestUriStations(Constants.EndPoint));
BindingContext = waterData;
var firstCity = waterData.WaterStation.Stations[0].NameEN;
}
I want to use waterData.WaterStation.Stations[0].NameEN;
or firstCity
in the constructor class.
My Constructor class:
public MainPage()
{
InitializeComponent();
_restServiceData = new RestServiceData();
_ = WaterDataForecast();
CustomPin pin1 = new CustomPin
{
Type = PinType.Place,
Position = new Position(41.59043006333251, 24.766286971618303),
Name = "Xamarin",
Label = "р. Бяла",
Address = "гр. Смолян",
CodeNum = 1,
AlertLevel = 2
};
CustomPin pin2 = new CustomPin
{
Type = PinType.Place,
Position = new Position(41.56817473054596, 24.758451447799708),
Label = "р. Черна",
Name = "Xamarin",
Address = "гр. Смолян",
CodeNum = 2,
AlertLevel = 2
};
customMap.CustomPins = new List<CustomPin> {
pin1,
pin2,
};
customMap.Pins.Add(pin1);
customMap.Pins.Add(pin2);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(41.567797926753485, 25.389703182725665), Distance.FromKilometers(70)));
DatabaseConnection(customMap.CustomPins);
}
I want to set firstCity
on label field in pin1
?
Can I get example how to do it ?
I initialize _ = WaterDataForecast(); in the constructor but how can I get waterData.WaterStation.Stations[0].NameEN and set on the label in the pin ?