故事板运行后无法将边框不透明度重置为 1.0,导致不透明度消失
在下面的示例中,边框内有一个文本块和一个按钮。按下按钮后,将调用 fadeBorder,并且边框及其中的所有内容都会很好地淡出。如果我尝试第二次调用 someMethod,边框不透明度仍然为 0,并且我看不到边框/消息/按钮。我尝试通过执行 myBorder.Opacity=1; 将其设置回 1;这对不透明度没有任何影响,在此行之后它仍然设置为 0。故事板完成后,是否有技巧可以将边框不透明度重置回 1.0?我还尝试将 double var 设置为 1.0,然后将该 var 分配给边框不透明度,但这也没有效果。
public void someMethod(string message) {
myTextBlock.Text = message;
myStackPanel.Children.Add(myTextBlock);
Ect... with Button Control and alignment of controls
fadeBorder();
protected void fadeBorder() {
var fade = new DoubleAnimation() {
From = 1,
To = 0,
Duration = TimeSpan.FromSeconds(this.secondsToFade),
};
Storyboard.SetTarget(fade, myBorder);
Storyboard.SetTargetProperty(fade, new PropertyPath(Border.OpacityProperty));
storyBoard.Children.Add(fade);
storyBoard.Begin();
}
In the example below, the border has a text block and a button inside. after the button is pressed, the fadeBorder is called and the border and everything in it fades nicely. If I try to call someMethod a 2nd time, the border opacity is still 0, and I can't see my border/message/button. I tried to set it back to one by doing myBorder.Opacity=1; This does not have any effect on the opacity, it's still set to 0 after this line. Is there a trick to resetting my Border opacity back to 1.0 after a storyboard has completed? I also tried setting a double var to 1.0, then assign that var to the border opacity, that did not have an effect either.
public void someMethod(string message) {
myTextBlock.Text = message;
myStackPanel.Children.Add(myTextBlock);
Ect... with Button Control and alignment of controls
fadeBorder();
protected void fadeBorder() {
var fade = new DoubleAnimation() {
From = 1,
To = 0,
Duration = TimeSpan.FromSeconds(this.secondsToFade),
};
Storyboard.SetTarget(fade, myBorder);
Storyboard.SetTargetProperty(fade, new PropertyPath(Border.OpacityProperty));
storyBoard.Children.Add(fade);
storyBoard.Begin();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何:使用情节提要进行动画处理后设置属性
How to: Set a Property After Animating It with a Storyboard