Example: When I press a button, I will display a painel
by editing only its visibility, it works, but it has no effect,
Then I had the idea of pressing the button to display the panel with opacity 0 and then increasing it gradually. But since the smartphone processor is fast and you can not see the effect, then I thought to deploy a sleep
, the result was that pressing the button takes about 2 seconds to display the panel, but displays it dry, without transition. sleep only slowed the button.
Code:
private void Button_Click(object sender, RoutedEventArgs e)
{ // Ao apertar o botão
if (painel.Visibility == System.Windows.Visibility.Visible)
{ //olha se o painel já está visivel
int cont = 200;
while (cont > 0)
{ // vai decrementando, e diminuindo sua opacidade
painel.Opacity = cont * 0.5;
System.Threading.Thread.Sleep(2); //tentativa de retardar um pouco
if (cont == 1) // quando a opacidade for 1 eu irei ocultar o painel
painel.Visibility = System.Windows.Visibility.Collapsed;
cont -= 1;
}
}
else
{ // se ao apertao do botão ele estiver oculto
int cont = 0;
painel.Visibility = System.Windows.Visibility.Visible; //torna ele visível
painel.Opacity = 0; // deixa com opacidade 0
while (cont < 100)
{ //vai aumentando a opacidade ate ela ser 99
painel.Opacity = cont * 0.5;
System.Threading.Thread.Sleep(2); / tentatida de retardar
cont += 1;
}
}
}
As I said, with sleep
, when I press the button it waits for 2 seconds and displays the panel without going controlling the opacity, it only displays it, without 'transition'. I'm deploying this in an app, where painel
is StackPanel
. It's an app for Windows Phone 8.1 with Silverlight.