title: Xamarin Forms: Stacklayout Visible with System.Timers
body: <p>I am on the most current version of Xamarin Forms. I have a Content Page. The Content Page has a grid that has a StackLayout and ScrollView. StackLayout Visible is false at the start point. When I click my Login Button, which has a Login method (see below) I set the StackLayout visible true. I use System.Timers too which start when login button clicked. If this timer reach 10 sec and the login isn't succesful the timer elapsed method activate. This method you can see below. At this point this work great, but I want to Login again and the StackLayout content doesn't show up. Can Anybody help me?  </p>
  
  <p>LoginPage.xml code: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
           x:Class="Spirocco.LoginPage"
           xmlns:renderer="clr-namespace:Spirocco.Droid.Renderers"&gt;
  &lt;Grid&gt;
      &lt;StackLayout x:Name="stackView" IsVisible="False" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="300" HeightRequest="50" BackgroundColor="LightGray" Orientation="Horizontal"&gt;
          &lt;ActivityIndicator IsRunning="True" Color="Black" HorizontalOptions="Center" Margin="20" HeightRequest="30" WidthRequest="30"/&gt;
          &lt;Label Text="Bejelentkezés..." TextColor="Black" VerticalOptions="Center" FontSize="16"/&gt;
      &lt;/StackLayout&gt;
      &lt;ScrollView Orientation="Both" x:Name="scrollView"&gt;
          &lt;ScrollView.Content&gt;
              &lt;StackLayout BackgroundColor="#302138"&gt;
                  &lt;Image Source="login_logo" Margin="0,0,0,0"&gt;&lt;/Image&gt;
                  &lt;StackLayout BackgroundColor="White" Margin="20,0,20,30"&gt;
                      &lt;Label Text="ÜDVÖZÖLJÜK!" FontSize="30" FontFamily="Comic Sans MS" Margin="0,15,0,0" TextColor="#302138" HorizontalTextAlignment="Center"&gt;&lt;/Label&gt;
                      &lt;renderer:BaseEntry x:Name="entryEmail" Text="{Binding Email}" Placeholder="E-mail" Margin="40,0,40,0" Keyboard="Email" ReturnType="Next"/&gt;
                      &lt;renderer:BaseEntry x:Name="entryPassword" Text="{Binding Password}" Placeholder="Jelszó" IsPassword="True" Margin="40,0,40,0" ReturnType="Send"/&gt;
                      &lt;Button Text="BEJELENTKEZÉS" Clicked="Login" TextColor="White" BackgroundColor="#302138" Margin="40,10,40,0"/&gt;
                      &lt;Button Text="REGISZTRÁCIÓ" Clicked="Register" TextColor="White" BackgroundColor="#302138" Margin="40,0,40,25"/&gt;
                  &lt;/StackLayout&gt;
                  &lt;Label BackgroundColor="#302138" HeightRequest="160"/&gt;
              &lt;/StackLayout&gt;
          &lt;/ScrollView.Content&gt;
      &lt;/ScrollView&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>My login method: </p>
  
  <pre><code>private async void Login(object sender, EventArgs e)
      {
          if (entryEmail.Text != null &amp;&amp; entryPassword.Text != null) 
          {
              try
              {
                  stackView.IsVisible = true;
                  scrollView.Opacity = 0.5;
                  timer = new Timer(10000);
                  timer.Start();
                  timer.Elapsed += SetContentViewVisible;
              }
              catch (Exception)
              {
                  stackView.IsVisible = false;
                  scrollView.Opacity = 1;
                  await DisplayAlert("Hiba történt", "Sikertelen bejelentkezés", "Vissza");
              }
          }
          else
          {
              await DisplayAlert("Bejelentkezés", "Sikertelen bejelentkezés, kérem a sikeres bejelentkezéshez töltse ki az e-mail cím és jelszó mezőt!", "Vissza");
          }
      }
  </code></pre>
  
  <p>SetContentViewVisible method: </p>
  
  <pre><code>private void SetContentViewVisible(object sender, ElapsedEventArgs e)
      {
          timer.Dispose();
          scrollView.Opacity = 1;
          stackView.IsVisible = false;
          timer.Stop();
      }
  </code></pre>