如何在 WPF 故事板中为静态对象添加动画效果

发布于 2024-07-10 08:00:38 字数 509 浏览 6 评论 0原文

我有一个 WPF 程序,需要添加“演示模式”。 由于我希望我的设计人员能够修改演示模式,而不必每次都重新编译程序,因此我认为使用外部 XAML 文件中的故事板是个好主意。 “演示模式”基本上是一个故事板,动画应用程序的一些依赖属性。

为了公开我的应用程序的 DP,我创建了应用程序类的公共静态成员(单例),以便应用程序的 DP 始终在外部可用。 在这种情况下,故事板将访问它们。

在外部 XAML 文件中,我添加了正确引用应用程序的命名空间/程序集的正确 xmlns。 因此理论上,我应该能够在 Storyboard 中访问应用程序的 DP。

问题是,当 XAML 中未声明/命名对象时,我不知道如何为 Storyboard 中的静态对象的 DP 制作动画。 声明故事板动画帧时,唯一的故事板附加属性是 Storyboard.TargetNameStoryboard.TargetProperty

如果有人能给我一个提示,让我朝着正确的方向前进,我将不胜感激。

I have a WPF program to which I need to add a "Demo mode". Since I want my designers to be able to modify the demo mode without me having to recompile the program each time, I tough it would be a great idea to use a storyboard from an external XAML file. The "Demo mode" is basically a storyboard animating some of the application's dependency properties.

To expose my application's DPs, I have created a public static member (singleton) of the application's class so that the application's DPs are always available externally. In this case, the storyboard will be accessing them.

In the external XAML file, I have added the proper xmlns referencing correctly the application's namespace/assembly. So in theory, I should be able to access the application's DP in a Storyboard.

The problem is that I don't know how to animate a DP of a static object in a Storyboard when the object is not declared/named in the XAML. When declaring a storyboard animation frame, the only storyboard's attached property are Storyboard.TargetName and Storyboard.TargetProperty.

I would appreciate if someone could give me a hint to get me in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海里的那抹蓝 2024-07-17 08:00:38

我还没有尝试过,但如果可行的话,我猜它看起来像这样:

<Storyboard ..>
    <DoubleAnimation Storyboard.Target="{x:Static MyNS:MyClass.Singleton}" 
                     Storyboard.TargetProperty="MyProperty" .../>
</Storyboard>

I haven't tried this out, but if it is doable I would guess it looks something like this:

<Storyboard ..>
    <DoubleAnimation Storyboard.Target="{x:Static MyNS:MyClass.Singleton}" 
                     Storyboard.TargetProperty="MyProperty" .../>
</Storyboard>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文