故事板运行后无法将边框不透明度重置为 1.0,导致不透明度消失

发布于 2024-10-30 23:51:01 字数 840 浏览 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文