, поэтому я пытаюсь сделать простую функцию для постепенного увеличения и уменьшения UIElement
проблема заключается в том, что элемент постепенно исчезает и имеет непрозрачность 1, но при исчезновении непрозрачность заканчивается на уровне около 0,01 против 0.
public static async Task<bool> FadeIO(UIElement target, int FadeTime = 100, int DelayBeforeFade = 5000, int DelayBeforeOutFade = 10000)
{
double OpacTick = 0; //The "counter" for the while loops.
double FadeAmount = ((double)1 / FadeTime); //Calculates the required opacity increment for the fade to happen in the specified time.
await Task.Delay(DelayBeforeFade); //Holds until the required delay before the fade has been reached.
do
{
target.Opacity = 0 + OpacTick; //Alters the target's opacity based on the current loop cylce.
OpacTick += FadeAmount; //Alters the counter by the pre calculated alteration amount.
await Task.Delay(1); //Halts the loop
} while (OpacTick <= 1); //Loops finished when the target's opacity is 1.
OpacTick = 0; //Resets the loop counter.
await Task.Delay(DelayBeforeOutFade); //Holds until the required delay before the fade out has been reached
do
{
target.Opacity = 1 - OpacTick; //Alters the target's opacity based on the current loop cylce.
OpacTick += FadeAmount; //Alters the counter by the pre calculated alteration amount.
await Task.Delay(1); //Halts the loop
} while (OpacTick <= 1); //Loops finished when the target's opacity is 0 and the counter is therefor 1.
return true;
}
Самым странным в этой проблеме является то, что при тестировании на разных системах непрозрачность может полностью возвращаться к 0, тогда как на некоторых системах она достигает около 0,01
.