title: Making a button visible after its past the current time using Xamarin.Forms
body: <p>I have a list-view which displays the current user medication schedule it currently sorts the list by the next due date and any medications that are past the current time are moved to the bottom of the list. </p>
  
  <p>I was looking to make the medications that are past the current time to have a 'Tomorrow' button visible to it. Is this possible to do? </p>
  
  <p>Currently this is how I am populating my listview:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Gets User Medication list
  /// &lt;/summary&gt;
  /// &lt;returns&gt;The user meds.&lt;/returns&gt;
  async public Task GetUserMedsOverdue()
  {
      MedicationListOverdue.ItemsSource = null;
      UserMedTimesOverdue.Clear(); //Clears the list before calling API (prevents duplication)
  
      main.Children.Add(MedicationListOverdue);
      main.Children.Remove(NoMeds);
  
      if (!CrossConnectivity.Current.IsConnected)
      {
          main.Children.Remove(MedicationListOverdue);
          main.Children.Add(NoMeds);
          NoMeds.Text = "No Internet Connection - Please check your connection";
          NoMeds.Margin = new Thickness(35, 35, 20, 20);
  
          BusyIndicator.IsRunning = false;
      }
  
      else
      {
          BusyIndicator.IsRunning = true;
          //var usermed = await medicinemanager.CurrentClient.InvokeApiAsync&lt;IEnumerable&lt;usermedication&gt;&gt;("getusermednamejoin?userid=" + Helpers.Settings.UserKey + "", System.Net.Http.HttpMethod.Get, null);
  
          try
          {
              var usermeddosagetimeoverdue = await medicinemanager.CurrentClient.InvokeApiAsync("getUserMedDosageTimeOverdue?userid=" + Helpers.Settings.UserKey, null, HttpMethod.Get, await App.LoadAPIKeyAsync(), null);
  
              var responseContentoverdue = await usermeddosagetimeoverdue.Content.ReadAsStringAsync();
              var useroverdue = JsonConvert.DeserializeObject&lt;ObservableCollection&lt;UserMedDosagePayLoadOverdue&gt;&gt;(responseContentoverdue);
  
              //var usermeddosagetime = await medicinemanager.CurrentClient.InvokeApiAsync&lt;IEnumerable&lt;UserMedDosagePayLoad&gt;&gt;("getusermeddosagetime?userid=" + Helpers.Settings.UserKey + "", HttpMethod.Get, API, System.Threading.CancellationToken.None);
              //null, System.Net.Http.HttpMethod.Get, API, System.Threading.CancellationToken.None);
  
              Debug.WriteLine("UserMedDosageTime" + usermeddosagetimeoverdue);
  
              foreach (UserMedDosagePayLoadOverdue item in useroverdue)
              {
                  UserMedTimesOverdue.Add(item);
              }
          }
          catch (Exception ex)
          {
              Debug.WriteLine(ex.ToString());
          }
  
          FindNextDue(UserMedTimes);
  
          //Get the List of meds the user is on
          //UserMedList = await usermedicationmanager.getUserMedication();
  
          //foreach (usermedication item in usermed)
          //{
          //    if (item.IsActive != false)
          //    {
          //        UserMedList.Add(item);
          //    }
          //}
  
          if (UserMedTimes.Count != 0)
          {
              MedicationListOverdue.ItemsSource = UserMedTimesOverdue;
              BusyIndicator.IsRunning = false;      
          }
  
          else
          {
              Label MedLogo = new Label();
              MedLogo.Text = peoplewithfonticon.meds;
              MedLogo.FontFamily = "icomoon";
              MedLogo.FontSize = 80;
              MedLogo.Margin = new Thickness(30, 80, 0, 0);
  
              Label MedTitle = new Label();
              MedTitle.Text = "No \r\nMedications";
              MedTitle.FontSize = 50;
              MedTitle.FontAttributes = FontAttributes.Bold;
              MedTitle.Margin = new Thickness(30, 0, 0, 0);
  
              Label NoMeds = new Label();
              NoMeds.Margin = new Thickness(30, 0, 0, 0);
              main.Children.Remove(MedicationList);
              //main.Children.Remove(btnHistory);
              main.Children.Add(MedLogo);
              main.Children.Add(MedTitle);
              main.Children.Add(NoMeds);
              NoMeds.Text = "You haven't added any medications to your medication cupboard yet";
              //main.Children.Add(btnHistory);
              BusyIndicator.IsRunning = false;
          }
  
          MedicationListOverdue.ItemsSource = UserMedTimesOverdue;
  
          BusyIndicator.IsRunning = false;
      }
  }
  </code></pre>
  
  <p>//Order the collection of times so the next due is always first</p>
  
  <pre><code>TimeComparison = new List&lt;TimeSpan&gt;(TimeComparison.OrderBy(h =&gt; h.Hours).ThenBy(m =&gt; m.Minutes));
  List&lt;string&gt; UserMedIDs = new List&lt;string&gt;();
  
  for (int i = 0; i &lt; TimeComparison.Count(); i++)
  {
      DateTime NextDue = DateTime.Now.Add(TimeComparison[i]);
      DateTime NextDueToCompare = new DateTime(NextDue.Year, NextDue.Month, NextDue.Day, NextDue.Hour, NextDue.Minute, 0);
      string NextDueComparisonString = NextDueToCompare.ToString("HH:mm:ss");
  
      foreach (UserMedDosagePayLoad item in UserMedTimes)
      {
          if (item.Time == NextDueComparisonString &amp;&amp; !UserMedIDs.Contains(item.Usermedid))
          {
              UserMedTimesFilteredList.Add(item);
              UserMedIDs.Add(item.Usermedid);                        
          }
      }
  
      UserMedTimes = medtimes;
      MedicationList.ItemsSource = UserMedTimesFilteredList.OrderBy(X =&gt; NextDue);
      BusyIndicator.IsRunning = false;
  }
  </code></pre>