2
Example: At the push of a button I’ll display a painel
editing only its visibility, it works, but is without any effect, is a dry transition.
Then I had the idea of pressing the button to display the panel with 0 opacity and then gradually incrementing it. But as the smartphone processor is fast you can’t even see the effect, so I thought about deploying a sleep
, the result was that pressing the button takes about 2 seconds to display the panel, but displays it dry, no transition, the Sleep just took the action of 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 the sleep
, When I press the button it waits a couple of seconds and displays the panel without going controlling the opacity, just displays it, without 'transition'. I’m implanting this into an app, where the painel
is a StackPanel
. It’s an app for Windows Phone 8.1 with Silverlight.
Ever thought of using Animations
– ramaral
I did not know of this method, fu by the reasoning of language itself, without methods, but thanks, I will test now, put results!
– Leonardo
It worked! At least to control the increasing opacity, ie to show the panel, to hide it with animation is still not working right, because I have to tone it Visible or Collapsed
– Leonardo
Got it, I’ll post the full answer
– Leonardo