gpt4 book ai didi

c# - StoryBoard - 从代码隐藏设置目标名称

转载 作者:可可西里 更新时间:2023-11-01 08:34:53 24 4
gpt4 key购买 nike

我在资源中有 Storyboard

  <Window.Resources>
<Storyboard x:Key="Fading" Storyboard.TargetName="NotifyWindow" Storyboard.TargetProperty="Opacity" >
<DoubleAnimation From="1" To="0" Duration="0:0:1">
</DoubleAnimation>
</Storyboard>
</Window.Resources>

在 WindowClosing 上我有下一个代码

private void NotifyWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Storyboard fading = this.Resources["Fading"] as Storyboard;
if (fading != null && !fadingCompleted)
{
fading.Completed += FadingStoryBoard_Completed;
fading.Begin();
e.Cancel = true;
}
}

private void FadingStoryBoard_Completed(object sender, EventArgs e)
{
fadingCompleted = true;
Close();
fadingCompleted = false;
}

这工作正常,但我想将这个 Storyboard移动到另一个程序集。所以我需要指定 StoryBoard.TargetName 表单代码。我该怎么做?

最佳答案

附加属性可以通过静态辅助方法从代码中设置:"Set"+ PropertyName

参见 C# 示例 here :

Storyboard.SetTargetName(yourAnimation, "NotifyWindow"); 

关于c# - StoryBoard - 从代码隐藏设置目标名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com