How to display weather icon in xamarin by calling Openweather API?

708 views Asked by At

I am working on a XAMARIN App. I am calling open weather API and able to get JSON response.

After string format, I am able to show the City Name + Temperature in the Header (Title).

Still i couldnt bind the Image Icon.

Whatever Bind Image works in the Content Page, but not on the Title.

This piece of syntax is from my Tabbed Main Page .. which calls City Tab Page.

 <NavigationPage Title="City" Icon="city.png">
    <x:Arguments>
      <local:CityPage />     
    </x:Arguments>
  </NavigationPage>

and in the city.xaml.cs - I am calling this method.

 public async void GetWeather()
        {
            Weather weather = await Core.GetWeather("07004");
            if (weather != null)
            {
                this.BindingContext = weather;

                string sWeather = String.Format("{0}°F", weather.Temperature);

                this.Title = weather.Title + " " + sWeather;             
            }

        }

enter image description here

Image Icon has to come at the end of the Temperature.

2

There are 2 answers

4
Jason On

you should be able to bind the url to an image

<ContentView Style="{StaticResource fieldView}">
  <StackLayout Orientation="Horizontal">
    <Label  x:Name="tempLabel" Text="{Binding Temperature}" Style="{StaticResource fieldStyle}" />
    <Image Source="{Binding DisplayIcon}" />
  </StackLayout>
</ContentView>
1
eakgul On

use StringFormat :

<Label Text={Binding Value, StringFormat='{0}° F'} ... />