Covid-19 App In Xamarin Forms
Hello guys.

In this article, we are creating an app, and this is the first part of the Covid-19 App. In this app we have the following pages.
  1. Global
  2. Home
  3. Covid-19 Search Countries
  4. About us
  5. CovidTabbedPage
Idea: During the COVID pandemic situation all over the world, I got an idea to develop an app which tracks records of the cases by counties and also show safety measures.
In this article, we have a COVID-19 App Global Page and Home Page, In the home page, we add a carousel view and cell view for showing the COVID-19 global data.
I am not going to describe the basic project setup steps here.
So let's design......
Global
In this Global page, we add one carousel and show the global data of COVID-19 like Total Cases, Total Recovery, Total Deaths and Total Active.
GlobalReport.xaml
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <ContentPage
  3. x:Class="Covid19.Views.GlobalReport"
  4. xmlns="http://xamarin.com/schemas/2014/forms"
  5. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  6. xmlns:customcontrols="clr-namespace:Covid19.CustomControls"
  7. xmlns:d="http://xamarin.com/schemas/2014/forms/design"
  8. xmlns:helper="clr-namespace:Covid19.Helper"
  9. xmlns:local="clr-namespace:Covid19"
  10. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  11. xmlns:pancakeview="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
  12. xmlns:rainbows="clr-namespace:Xamarin.Forms.DebugRainbows;assembly=Xamarin.Forms.DebugRainbows"
  13. rainbows:DebugRainbow.ShowColors="False"
  14. BackgroundColor="White"
  15. Visual="Material"
  16. mc:Ignorable="d">
  17. <ContentPage.Content>
  18. <Grid>
  19. <Grid.RowDefinitions>
  20. <RowDefinition Height="25" />
  21. <RowDefinition Height="25" />
  22. <RowDefinition Height="*" />
  23. </Grid.RowDefinitions>
  24. <Grid.ColumnDefinitions>
  25. <ColumnDefinition Width="*" />
  26. </Grid.ColumnDefinitions>
  27. <Label
  28. Grid.Row="1"
  29. Grid.Column="0"
  30. Margin="10,0,0,0"
  31. FontFamily="OpenSansBold"
  32. FontSize="20"
  33. Text="Covid-19" />
  34. <Grid Grid.Row="2" Grid.Column="0">
  35. <Grid.RowDefinitions>
  36. <RowDefinition Height="0.35*" />
  37. <RowDefinition Height="*" />
  38. </Grid.RowDefinitions>
  39. <Grid.ColumnDefinitions>
  40. <ColumnDefinition Width="*" />
  41. </Grid.ColumnDefinitions>
  42. <StackLayout
  43. Grid.Row="0"
  44. Grid.Column="0"
  45. HorizontalOptions="CenterAndExpand"
  46. VerticalOptions="CenterAndExpand">
  47. <CarouselView
  48. HorizontalOptions="FillAndExpand"
  49. IndicatorView="indicatorView"
  50. ItemsSource="{Binding CarouselList}"
  51. VerticalOptions="CenterAndExpand">
  52. <CarouselView.ItemTemplate>
  53. <DataTemplate>
  54. <StackLayout
  55. Padding="0"
  56. HorizontalOptions="Center"
  57. Spacing="0"
  58. VerticalOptions="Center">
  59. <Frame
  60. Margin="20"
  61. Padding="0"
  62. BackgroundColor="Red"
  63. BorderColor="White"
  64. CornerRadius="25"
  65. HasShadow="true"
  66. HeightRequest="120"
  67. Visual="Material">
  68. <Image Aspect="AspectFill" Source="{Binding .}" />
  69. </Frame>
  70. </StackLayout>
  71. </DataTemplate>
  72. </CarouselView.ItemTemplate>
  73. </CarouselView>
  74. <!--<Frame
  75. Padding="3"
  76. BackgroundColor="#999FBF"
  77. CornerRadius="15"
  78. HorizontalOptions="Center"
  79. VerticalOptions="Center">-->
  80. <IndicatorView
  81. x:Name="indicatorView"
  82. HorizontalOptions="Center"
  83. IndicatorColor="#999FBF"
  84. IndicatorsShape="Circle"
  85. SelectedIndicatorColor="#4C79FF"
  86. VerticalOptions="Start" />
  87. <!--</Frame>-->
  88. </StackLayout>
  89. <ScrollView Grid.Row="1" Grid.Column="0">
  90. <Grid Padding="10" RowSpacing="15">
  91. <Grid.RowDefinitions>
  92. <RowDefinition Height="{OnPlatform Android=85, iOS=100}" />
  93. <RowDefinition Height="{OnPlatform Android=85, iOS=100}" />
  94. <RowDefinition Height="{OnPlatform Android=85, iOS=100}" />
  95. <RowDefinition Height="{OnPlatform Android=85, iOS=100}" />
  96. </Grid.RowDefinitions>
  97. <Grid.ColumnDefinitions>
  98. <ColumnDefinition Width="*" />
  99. </Grid.ColumnDefinitions>
  100. <Frame
  101. Grid.Row="0"
  102. Grid.Column="0"
  103. Padding="10,0"
  104. BackgroundColor="White"
  105. BorderColor="LightGray"
  106. CornerRadius="10"
  107. Visual="Material">
  108. <Grid Padding="10" RowSpacing="5">
  109. <Grid.RowDefinitions>
  110. <RowDefinition Height="4*" />
  111. <RowDefinition Height="6*" />
  112. </Grid.RowDefinitions>
  113. <Grid.ColumnDefinitions>
  114. <ColumnDefinition Width="*" />
  115. <ColumnDefinition Width="Auto" />
  116. </Grid.ColumnDefinitions>
  117. <Label
  118. Grid.Row="0"
  119. Grid.Column="0"
  120. Style="{StaticResource SmallLabelStyle}"
  121. Text="Total Cases"
  122. TextColor="#EEA445" />
  123. <ActivityIndicator
  124. Grid.Row="1"
  125. Grid.Column="0"
  126. Margin="0,5"
  127. HorizontalOptions="Start"
  128. IsRunning="{Binding IsBussy}"
  129. IsVisible="{Binding IsBussy}"
  130. Color="#EEA445" />
  131. <Label
  132. Grid.Row="1"
  133. Grid.Column="0"
  134. Style="{StaticResource MediumLabelStyle}"
  135. Text="{Binding GlobalCovid.cases, StringFormat='{0:N0}'}"
  136. TextColor="#EEA445" />
  137. <ImageButton
  138. Grid.Row="0"
  139. Grid.RowSpan="2"
  140. Grid.Column="1"
  141. Padding="10"
  142. Aspect="AspectFit"
  143. BackgroundColor="#FEDADC"
  144. BorderColor="#EEA445"
  145. BorderWidth="1"
  146. CornerRadius="25"
  147. HeightRequest="50"
  148. HorizontalOptions="CenterAndExpand"
  149. IsEnabled="False"
  150. Source="{local:ImageResource Covid19.Resources.covid19.png}"
  151. VerticalOptions="CenterAndExpand"
  152. WidthRequest="50" />
  153. </Grid>
  154. </Frame>
  155. <Frame
  156. Grid.Row="1"
  157. Grid.Column="0"
  158. Padding="10,0"
  159. BackgroundColor="White"
  160. BorderColor="LightGray"
  161. CornerRadius="10"
  162. Visual="Material">
  163. <Grid Padding="10">
  164. <Grid.RowDefinitions>
  165. <RowDefinition Height="4*" />
  166. <RowDefinition Height="6*" />
  167. </Grid.RowDefinitions>
  168. <Grid.ColumnDefinitions>
  169. <ColumnDefinition Width="*" />
  170. <ColumnDefinition Width="Auto" />
  171. </Grid.ColumnDefinitions>
  172. <Label
  173. Grid.Row="0"
  174. Grid.Column="0"
  175. Style="{StaticResource SmallLabelStyle}"
  176. Text="Total Recovery"
  177. TextColor="#1FD34E" />
  178. <ActivityIndicator
  179. Grid.Row="1"
  180. Grid.Column="0"
  181. Margin="0,5"
  182. HorizontalOptions="Start"
  183. IsRunning="{Binding IsBussy}"
  184. IsVisible="{Binding IsBussy}"
  185. Color="#1FD34E" />
  186. <Label
  187. Grid.Row="1"
  188. Grid.Column="0"
  189. Style="{StaticResource MediumLabelStyle}"
  190. Text="{Binding GlobalCovid.recovered, StringFormat='{0:N0}'}"
  191. TextColor="#1FD34E" />
  192. <ImageButton
  193. Grid.Row="0"
  194. Grid.RowSpan="2"
  195. Grid.Column="1"
  196. Padding="10"
  197. Aspect="AspectFit"
  198. BackgroundColor="#D6F4DC"
  199. BorderColor="#1FD34E"
  200. BorderWidth="1"
  201. CornerRadius="25"
  202. HeightRequest="50"
  203. HorizontalOptions="CenterAndExpand"
  204. IsEnabled="False"
  205. Source="{FontImage FontFamily=FontAwesome,
  206. Glyph={x:Static helper:IconFont.Heart},
  207. Size=40,
  208. Color='#21CF55'}"
  209. VerticalOptions="CenterAndExpand"
  210. WidthRequest="50" />
  211. </Grid>
  212. </Frame>
  213. <Frame
  214. Grid.Row="2"
  215. Grid.Column="0"
  216. Padding="10,0"
  217. BackgroundColor="White"
  218. BorderColor="LightGray"
  219. CornerRadius="10"
  220. Visual="Material">
  221. <Grid Padding="10">
  222. <Grid.RowDefinitions>
  223. <RowDefinition Height="4*" />
  224. <RowDefinition Height="6*" />
  225. </Grid.RowDefinitions>
  226. <Grid.ColumnDefinitions>
  227. <ColumnDefinition Width="*" />
  228. <ColumnDefinition Width="Auto" />
  229. </Grid.ColumnDefinitions>
  230. <Label
  231. Grid.Row="0"
  232. Grid.Column="0"
  233. Style="{StaticResource SmallLabelStyle}"
  234. Text="Total Deaths"
  235. TextColor="#EF3936" />
  236. <ActivityIndicator
  237. Grid.Row="1"
  238. Grid.Column="0"
  239. Margin="0,5"
  240. HorizontalOptions="Start"
  241. IsRunning="{Binding IsBussy}"
  242. IsVisible="{Binding IsBussy}"
  243. Color="#EF3936" />
  244. <Label
  245. Grid.Row="1"
  246. Grid.Column="0"
  247. Style="{StaticResource MediumLabelStyle}"
  248. Text="{Binding GlobalCovid.deaths, StringFormat='{0:N0}'}"
  249. TextColor="#EF3936" />
  250. <ImageButton
  251. Grid.Row="0"
  252. Grid.RowSpan="2"
  253. Grid.Column="1"
  254. Padding="15"
  255. Aspect="AspectFit"
  256. BackgroundColor="#FADEDA"
  257. BorderColor="#EF3936"
  258. BorderWidth="1"
  259. CornerRadius="25"
  260. HeightRequest="50"
  261. HorizontalOptions="CenterAndExpand"
  262. IsEnabled="False"
  263. Source="{FontImage FontFamily=FontAwesome,
  264. Glyph={x:Static helper:IconFont.Close},
  265. Size=40,
  266. Color=Red}"
  267. VerticalOptions="CenterAndExpand"
  268. WidthRequest="50" />
  269. </Grid>
  270. </Frame>
  271. <Frame
  272. Grid.Row="3"
  273. Grid.Column="0"
  274. Padding="10,0"
  275. BackgroundColor="White"
  276. BorderColor="LightGray"
  277. CornerRadius="10"
  278. Visual="Material">
  279. <Grid Padding="10">
  280. <Grid.RowDefinitions>
  281. <RowDefinition Height="4*" />
  282. <RowDefinition Height="6*" />
  283. </Grid.RowDefinitions>
  284. <Grid.ColumnDefinitions>
  285. <ColumnDefinition Width="*" />
  286. <ColumnDefinition Width="Auto" />
  287. </Grid.ColumnDefinitions>
  288. <Label
  289. Grid.Row="0"
  290. Grid.Column="0"
  291. Style="{StaticResource SmallLabelStyle}"
  292. Text="Total Active"
  293. TextColor="#0A7FF3" />
  294. <ActivityIndicator
  295. Grid.Row="1"
  296. Grid.Column="0"
  297. Margin="0,5"
  298. HorizontalOptions="Start"
  299. IsRunning="{Binding IsBussy}"
  300. IsVisible="{Binding IsBussy}"
  301. Color="#0A7FF3" />
  302. <Label
  303. Grid.Row="1"
  304. Grid.Column="0"
  305. Style="{StaticResource MediumLabelStyle}"
  306. Text="{Binding GlobalCovid.active, StringFormat='{0:N0}'}"
  307. TextColor="#0A7FF3" />
  308. <ImageButton
  309. Grid.Row="0"
  310. Grid.RowSpan="2"
  311. Grid.Column="1"
  312. Padding="10"
  313. Aspect="AspectFit"
  314. BackgroundColor="#CFE3FC"
  315. BorderColor="#0A7FF3"
  316. BorderWidth="1"
  317. CornerRadius="25"
  318. HeightRequest="50"
  319. HorizontalOptions="CenterAndExpand"
  320. IsEnabled="False"
  321. Source="{local:ImageResource Covid19.Resources.active.png}"
  322. VerticalOptions="CenterAndExpand"
  323. WidthRequest="50" />
  324. </Grid>
  325. </Frame>
  326. </Grid>
  327. </ScrollView>
  328. </Grid>
  329. </Grid>
  330. </ContentPage.Content>
  331. </ContentPage>
Now we are creating the ViewModel for the binding the data with a view.
GloalViewModel.cs
  1. using Covid19.Models;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Diagnostics;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Net.Http.Headers;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Xamarin.Forms;
  14. namespace Covid19.ViewModel
  15. {
  16. public class GloalViewModel:BaseViewModel
  17. {
  18. public GloalViewModel()
  19. {
  20. GetGlobalCoronaDataCommand.Execute(null);
  21. CarouselList = new List<string>() { "darkcar01.png", "darkcar02.png", "darkcar03.png" };
  22. }
  23. #region Properties
  24. private bool isbussy=false;
  25. public bool IsBussy
  26. {
  27. get { return isbussy; }
  28. set { isbussy = value; RaisePropertyChanged(() =>IsBussy); }
  29. }
  30. private List<string> carouselList;
  31. public List<string> CarouselList
  32. {
  33. get { return carouselList; }
  34. set { carouselList = value; RaisePropertyChanged(() => CarouselList); }
  35. }
  36. private CountryModel globalcovid;
  37. public CountryModel GlobalCovid
  38. {
  39. get { return globalcovid; }
  40. set { globalcovid = value; RaisePropertyChanged(() => GlobalCovid); }
  41. }
  42. private List<CountryModel> allcountry;
  43. public List<CountryModel> AllCountry
  44. {
  45. get { return allcountry; }
  46. set { allcountry = value; RaisePropertyChanged(() => AllCountry); }
  47. }
  48. private ObservableCollection<CountryModel> searchcountry;
  49. public ObservableCollection<CountryModel> SearchCountry
  50. {
  51. get { return searchcountry; }
  52. set { searchcountry = value; RaisePropertyChanged(() => SearchCountry); }
  53. }
  54. private List<CountryFlag> countryflags;
  55. public List<CountryFlag> CountryFlags
  56. {
  57. get { return countryflags; }
  58. set { countryflags = value;RaisePropertyChanged(()=>CountryFlags); }
  59. }
  60. #endregion
  61. #region Commands
  62. public Command GetGlobalCoronaDataCommand => new Command(async()=>await GetGlobalCoronaDataCommandExecution());
  63. #endregion
  64. #region CommandExecution
  65. private async Task GetGlobalCoronaDataCommandExecution()
  66. {
  67. var current = Xamarin.Essentials.Connectivity.NetworkAccess;
  68. if (current != Xamarin.Essentials.NetworkAccess.Internet)
  69. UserDialogs.Instance.Alert("Please Check the internet connection", "Network Error", "OK");
  70. else
  71. {
  72. IsBussy = true;
  73. // UserDialogs.Instance.ShowLoading();
  74. await Task.Delay(1000);
  75. using (var client = new HttpClient())
  76. {
  77. try
  78. {
  79. client.BaseAddress = new Uri("https://coronavirus-19-api.herokuapp.com/");
  80. client.DefaultRequestHeaders.Accept.Clear();
  81. client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  82. //GET Method
  83. HttpResponseMessage result = await client.GetAsync("countries");
  84. if (result.IsSuccessStatusCode)
  85. {
  86. var rawResult = result.Content.ReadAsStringAsync().Result;
  87. AllCountry = JsonConvert.DeserializeObject<List<CountryModel>>(rawResult);
  88. SearchCountry = new ObservableCollection<CountryModel>(AllCountry);
  89. GlobalCovid = AllCountry.Where(e => e.country == "World").SingleOrDefault();
  90. App.AppSetup.HomeViewModel.Country = AllCountry.Where(e => e.country == "India").SingleOrDefault();
  91. IsBussy = false;
  92. }
  93. else
  94. {
  95. IsBussy = false;
  96. UserDialogs.Instance.Alert("Internal server Error", "Server Error", "OK");
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. //UserDialogs.Instance.Alert("Internal Error", $"Internal Error {ex.Message}", "OK");
  102. }
  103. }
  104. }
  105. }
  106. #endregion
  107. }
  108. }
Covid-19 App In Xamarin Forms
Home Report
In this Home page, we add the redirecting button for the social app (MyGov Corona) and show the home country (India) data of COVID-19 like Total Cases, Total Recovery, Total Deaths and Total Active.
HomeReport.xaml
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <ContentPage
  3. x:Class="Covid19.Views.HomeReport"
  4. xmlns="http://xamarin.com/schemas/2014/forms"
  5. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  6. xmlns:customcontrols="clr-namespace:Covid19.CustomControls"
  7. xmlns:d="http://xamarin.com/schemas/2014/forms/design"
  8. xmlns:helper="clr-namespace:Covid19.Helper"
  9. xmlns:local="clr-namespace:Covid19"
  10. xmlns:local1="clr-namespace:Covid19.CustomCells"
  11. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  12. xmlns:rainbows="clr-namespace:Xamarin.Forms.DebugRainbows;assembly=Xamarin.Forms.DebugRainbows"
  13. rainbows:DebugRainbow.ShowColors="False"
  14. BackgroundColor="White"
  15. Visual="Material"
  16. mc:Ignorable="d">
  17. <ContentPage.Content>
  18. <ScrollView>
  19. <Grid Padding="0,0,0,10">
  20. <Grid.RowDefinitions>
  21. <RowDefinition Height="0.45*" />
  22. <RowDefinition Height="0.55*" />
  23. </Grid.RowDefinitions>
  24. <Grid.ColumnDefinitions>
  25. <ColumnDefinition Width="Auto" />
  26. </Grid.ColumnDefinitions>
  27. <Grid
  28. Grid.Row="0"
  29. Grid.Column="0"
  30. Padding="35,15"
  31. BackgroundColor="#473F97">
  32. <Grid.RowDefinitions>
  33. <RowDefinition Height="25" />
  34. <RowDefinition Height="1.5*" />
  35. <RowDefinition Height="6.5*" />
  36. <RowDefinition Height="2*" />
  37. </Grid.RowDefinitions>
  38. <Grid Grid.Row="1" Grid.Column="0">
  39. <Grid.ColumnDefinitions>
  40. <ColumnDefinition Width="*" />
  41. <ColumnDefinition Width="*" />
  42. </Grid.ColumnDefinitions>
  43. <Label
  44. Grid.Row="0"
  45. Grid.Column="0"
  46. FontFamily="OpenSansBold"
  47. FontSize="25"
  48. HorizontalOptions="StartAndExpand"
  49. Text="Covid-19"
  50. TextColor="White"
  51. VerticalOptions="Center" />
  52. <Button
  53. Grid.Row="0"
  54. Grid.Column="1"
  55. BackgroundColor="White"
  56. CornerRadius="25"
  57. HorizontalOptions="EndAndExpand" ImageSource="https://www.countryflags.io/in/flat/64.png"
  58. Text=" India "
  59. TextColor="#473F97" />
  60. </Grid>
  61. <Grid
  62. Grid.Row="2"
  63. Grid.Column="0"
  64. RowSpacing="0">
  65. <Grid.RowDefinitions>
  66. <RowDefinition Height="Auto" />
  67. <RowDefinition Height="*" />
  68. </Grid.RowDefinitions>
  69. <Label
  70. Grid.Row="0"
  71. Grid.Column="0"
  72. FontFamily="OpenSansBold"
  73. FontSize="25"
  74. Text="What is Covid-19?"
  75. TextColor="White" />
  76. <Label
  77. Grid.Row="1"
  78. Grid.Column="0"
  79. FontFamily="OpenSansRegular"
  80. FontSize="15"
  81. HorizontalOptions="StartAndExpand"
  82. Text="COVID-19 is the infectious disease caused by the most recently discovered corona virus. This new virus and disease were unknown before the outbreak began in Wuhan, China, in December 2019."
  83. TextColor="White"
  84. VerticalOptions="Center" />
  85. </Grid>
  86. <Grid
  87. Grid.Row="3"
  88. Grid.Column="0"
  89. ColumnSpacing="20">
  90. <Grid.ColumnDefinitions>
  91. <ColumnDefinition Width="0.2*" />
  92. <ColumnDefinition Width="0.2*" />
  93. <ColumnDefinition Width="0.2*" />
  94. <ColumnDefinition Width="0.2*" />
  95. <ColumnDefinition Width="0.2*" />
  96. </Grid.ColumnDefinitions>
  97. <Grid.RowDefinitions>
  98. <RowDefinition Height="52" />
  99. </Grid.RowDefinitions>
  100. <Button
  101. Grid.Row="0"
  102. Grid.Column="0"
  103. BackgroundColor="White"
  104. Command="{Binding WhatsAppCommand}"
  105. CornerRadius="{OnPlatform Android=25,
  106. iOS=25}"
  107. HorizontalOptions="EndAndExpand"
  108. ImageSource="{FontImage FontFamily=FontAwesome,
  109. Glyph={x:Static helper:IconFont.Whatsapp},
  110. Size=30,
  111. Color='#4FCE5D'}" />
  112. <Button
  113. Grid.Row="0"
  114. Grid.Column="1"
  115. BackgroundColor="White"
  116. Command="{Binding MessengerCommand}"
  117. CornerRadius="25"
  118. HorizontalOptions="EndAndExpand"
  119. ImageSource="{FontImage FontFamily=FontAwesome,
  120. Glyph={x:Static helper:IconFont.FacebookMessenger},
  121. Size=30,
  122. Color='#1B7ACD'}" />
  123. <Button
  124. Grid.Row="0"
  125. Grid.Column="2"
  126. BackgroundColor="White"
  127. Command="{Binding TelegramCommand}"
  128. CornerRadius="25"
  129. HorizontalOptions="EndAndExpand"
  130. ImageSource="{FontImage FontFamily=FontAwesome,
  131. Glyph={x:Static helper:IconFont.Telegram},
  132. Size=30,
  133. Color='#64B5F6'}" />
  134. <Button
  135. Grid.Row="0"
  136. Grid.Column="3"
  137. BackgroundColor="White"
  138. Command="{Binding InstagramCommand}"
  139. CornerRadius="25"
  140. HorizontalOptions="EndAndExpand"
  141. ImageSource="{FontImage FontFamily=FontAwesome,
  142. Glyph={x:Static helper:IconFont.Instagram},
  143. Size=30,
  144. Color='#E74265'}" />
  145. <Button
  146. Grid.Row="0"
  147. Grid.Column="4"
  148. BackgroundColor="White"
  149. Command="{Binding FBCommand}"
  150. CornerRadius="25"
  151. HorizontalOptions="EndAndExpand"
  152. ImageSource="{FontImage FontFamily=FontAwesome,
  153. Glyph={x:Static helper:IconFont.Facebook},
  154. Size=30,
  155. Color='#2E4780'}" />
  156. </Grid>
  157. </Grid>
  158. <Grid
  159. Grid.Row="1"
  160. Grid.Column="0"
  161. Padding="20"
  162. ColumnSpacing="10"
  163. HorizontalOptions="FillAndExpand"
  164. RowSpacing="10"
  165. VerticalOptions="FillAndExpand">
  166. <Grid.ColumnDefinitions>
  167. <ColumnDefinition Width="5*" />
  168. <ColumnDefinition Width="5*" />
  169. </Grid.ColumnDefinitions>
  170. <Grid.RowDefinitions>
  171. <RowDefinition Height="5*" />
  172. <RowDefinition Height="5*" />
  173. </Grid.RowDefinitions>
  174. <Frame
  175. Grid.Row="0"
  176. Grid.Column="0"
  177. Padding="10"
  178. BackgroundColor="White"
  179. BorderColor="LightGray"
  180. CornerRadius="10">
  181. <StackLayout Padding="10" Spacing="0">
  182. <Grid RowSpacing="5">
  183. <Grid.RowDefinitions>
  184. <RowDefinition Height="Auto" />
  185. <RowDefinition Height="Auto" />
  186. </Grid.RowDefinitions>
  187. <Label
  188. Grid.Row="0"
  189. Grid.Column="0"
  190. Style="{StaticResource SmallLabelStyle}"
  191. Text="Total Cases"
  192. TextColor="#EEA445" />
  193. <Label
  194. Grid.Row="1"
  195. Grid.Column="0"
  196. Style="{StaticResource MediumLabelStyle}"
  197. Text="{Binding Country.cases, StringFormat='{0:N0}'}"
  198. TextColor="#EEA445" />
  199. </Grid>
  200. <ImageButton
  201. Padding="10"
  202. Aspect="AspectFit"
  203. BackgroundColor="#FEDADC"
  204. BorderColor="#EEA445"
  205. BorderWidth="1"
  206. CornerRadius="{OnPlatform Android=25,
  207. iOS=18}"
  208. HeightRequest="35"
  209. HorizontalOptions="End"
  210. IsEnabled="False"
  211. Source="{local:ImageResource Covid19.Resources.covid19.png}"
  212. VerticalOptions="EndAndExpand"
  213. WidthRequest="35" />
  214. </StackLayout>
  215. </Frame>
  216. <Frame
  217. Grid.Row="0"
  218. Grid.Column="1"
  219. Padding="10"
  220. BackgroundColor="White"
  221. BorderColor="LightGray"
  222. CornerRadius="10">
  223. <StackLayout Padding="5" Spacing="0">
  224. <Grid RowSpacing="5">
  225. <Grid.RowDefinitions>
  226. <RowDefinition Height="Auto" />
  227. <RowDefinition Height="Auto" />
  228. </Grid.RowDefinitions>
  229. <Label
  230. Grid.Row="0"
  231. Grid.Column="0"
  232. Style="{StaticResource SmallLabelStyle}"
  233. Text="Total Recover"
  234. TextColor="#1FD34E" />
  235. <Label
  236. Grid.Row="1"
  237. Grid.Column="0"
  238. Style="{StaticResource MediumLabelStyle}"
  239. Text="{Binding Country.recovered, StringFormat='{0:N0}'}"
  240. TextColor="#1FD34E" />
  241. </Grid>
  242. <ImageButton
  243. Padding="10"
  244. Aspect="AspectFit"
  245. BackgroundColor="#D6F4DC"
  246. BorderColor="#1FD34E"
  247. BorderWidth="1"
  248. CornerRadius="{OnPlatform Android=25,
  249. iOS=18}"
  250. HeightRequest="35"
  251. HorizontalOptions="End"
  252. IsEnabled="False"
  253. Source="{FontImage FontFamily=FontAwesome,
  254. Glyph={x:Static helper:IconFont.Heart},
  255. Size=40,
  256. Color='#21CF55'}"
  257. VerticalOptions="EndAndExpand"
  258. WidthRequest="35" />
  259. </StackLayout>
  260. </Frame>
  261. <Frame
  262. Grid.Row="1"
  263. Grid.Column="0"
  264. Padding="10"
  265. BackgroundColor="White"
  266. BorderColor="LightGray"
  267. CornerRadius="10">
  268. <StackLayout Padding="10" Spacing="0">
  269. <Grid RowSpacing="5">
  270. <Grid.RowDefinitions>
  271. <RowDefinition Height="Auto" />
  272. <RowDefinition Height="Auto" />
  273. </Grid.RowDefinitions>
  274. <Label
  275. Grid.Row="0"
  276. Grid.Column="0"
  277. Style="{StaticResource SmallLabelStyle}"
  278. Text="Total Deaths"
  279. TextColor="#EF3936" />
  280. <Label
  281. Grid.Row="1"
  282. Grid.Column="0"
  283. Style="{StaticResource MediumLabelStyle}"
  284. Text="{Binding Country.deaths, StringFormat='{0:N0}'}"
  285. TextColor="#EF3936" />
  286. </Grid>
  287. <ImageButton
  288. Padding="10"
  289. Aspect="AspectFit"
  290. BackgroundColor="#FADEDA"
  291. BorderColor="#EF3936"
  292. BorderWidth="1"
  293. CornerRadius="{OnPlatform Android=25,
  294. iOS=18}"
  295. HeightRequest="35"
  296. HorizontalOptions="End"
  297. IsEnabled="False"
  298. Source="{FontImage FontFamily=FontAwesome,
  299. Glyph={x:Static helper:IconFont.Close},
  300. Size=40,
  301. Color=Red}"
  302. VerticalOptions="EndAndExpand"
  303. WidthRequest="35" />
  304. </StackLayout>
  305. </Frame>
  306. <Frame
  307. Grid.Row="1"
  308. Grid.Column="1"
  309. Padding="10"
  310. BackgroundColor="White"
  311. BorderColor="LightGray"
  312. CornerRadius="10">
  313. <StackLayout Padding="10" Spacing="0">
  314. <Grid RowSpacing="5">
  315. <Grid.RowDefinitions>
  316. <RowDefinition Height="Auto" />
  317. <RowDefinition Height="Auto" />
  318. </Grid.RowDefinitions>
  319. <Label
  320. Grid.Row="0"
  321. Grid.Column="0"
  322. Style="{StaticResource SmallLabelStyle}"
  323. Text="Active Cases"
  324. TextColor="#0A7FF3" />
  325. <Label
  326. Grid.Row="1"
  327. Grid.Column="0"
  328. Style="{StaticResource MediumLabelStyle}"
  329. Text="{Binding Country.active, StringFormat='{0:N0}'}"
  330. TextColor="#0A7FF3" />
  331. </Grid>
  332. <ImageButton
  333. Padding="10"
  334. Aspect="AspectFit"
  335. BackgroundColor="#CFE3FC"
  336. BorderColor="#0A7FF3"
  337. BorderWidth="1"
  338. CornerRadius="{OnPlatform Android=25,
  339. iOS=18}"
  340. HeightRequest="35"
  341. HorizontalOptions="End"
  342. IsEnabled="False"
  343. Source="{local:ImageResource Covid19.Resources.active.png}"
  344. VerticalOptions="EndAndExpand"
  345. WidthRequest="35" />
  346. </StackLayout>
  347. </Frame>
  348. </Grid>
  349. </Grid>
  350. </ScrollView>
  351. </ContentPage.Content>
  352. </ContentPage>
Now we are creating the ViewModel(HomeViewModel) and binding the data with a view.
HomeViewModel.cs
  1. public class HomeViewModel:BaseViewModel
  2. {
  3. public HomeViewModel { }
  4. #region Properties
  5. private CountryModel country;
  6. public CountryModel Country
  7. {
  8. get { return country; }
  9. set {country = value; RaisePropertyChanged(() => Country); }
  10. }
  11. #endregion
  12. #region Commands
  13. public Command WhatsAppCommand => new Command(() => Device.OpenUri(new Uri("https://api.whatsapp.com/send?phone=919013353535")));
  14. public Command TelegramCommand => new Command(() => Device.OpenUri(new Uri("tg://resolve?domain=MyGovCoronaNewsdesk")));
  15. public Command InstagramCommand => new Command(() => Device.OpenUri(new Uri("instagram://user?username=mygovindia")));
  16. public Command FBCommand => new Command(() => Device.OpenUri(new Uri("fb://group/224193992332793")));
  17. public Command MessengerCommand => new Command(() => Device.OpenUri(new Uri("http://m.me/MyGovIndia")));
  18. #endregion
  19. }
Covid-19 App In Xamarin Forms
That's it for this article, we will cover more in the next article.
If you want to see part 2 click here.