WPF 动画上的 DataTrigger

发布于 2024-10-07 15:15:40 字数 1080 浏览 0 评论 0原文

我的应用程序有一些后台工作人员,每个人都做不同的工作。当我单击“开始”按钮时,所有后台工作人员将同时启动。

在我的 xaml 中,我定义了旋转图像的动画:

<window.Resources>
    <Storyboard x:Key="imageRotate">
        <DoubleAnimation Storyboard.TargetName="transRotate"
                Storyboard.TargetProperty="(Image.RenderTransform).(RotateTransform.Angle)"
                From="0" To="360"
                Duration="0:0:0.5"
                AutoReverse="False"
                RepeatBehavior="Forever"/>
     </Storyboard>
</window.Resources>

我希望动画在所有后台工作人员启动时开始,并仅在所有后台工作人员停止后停止。

我有一个名为 AreWorkersBusy: 的属性,

private bool _areWorkerBusy;
public bool AreWorkerBusy
{
    get
    {
        return _areWorkerBusy;
    }
    set
    {
        bool isBusy = false;
        foreach(BackgroundWorker worker in BackgroundWorkerList)
        {
            if(worker.IsBusy)
                 isBusy = true;
        }
        _areWorkerBusy = isBusy;
    }
}

但它不是 dependencyProperty,因此我无法绑定到动画的 DataTrigger。

有什么解决办法吗???

帮助!

My application has a few background worker, each doing different work. When I click the 'Start' button, all backgroundworker will start simultaneously.

in my xaml, I had defined my animation of a rotate image:

<window.Resources>
    <Storyboard x:Key="imageRotate">
        <DoubleAnimation Storyboard.TargetName="transRotate"
                Storyboard.TargetProperty="(Image.RenderTransform).(RotateTransform.Angle)"
                From="0" To="360"
                Duration="0:0:0.5"
                AutoReverse="False"
                RepeatBehavior="Forever"/>
     </Storyboard>
</window.Resources>

I want the animation to begin when all the backgroundworker started, and stop ONLY after ALL background worker stopped.

I have a property call AreWorkersBusy:

private bool _areWorkerBusy;
public bool AreWorkerBusy
{
    get
    {
        return _areWorkerBusy;
    }
    set
    {
        bool isBusy = false;
        foreach(BackgroundWorker worker in BackgroundWorkerList)
        {
            if(worker.IsBusy)
                 isBusy = true;
        }
        _areWorkerBusy = isBusy;
    }
}

but it's not dependencyProperty, so I can't bind to my animation's DataTrigger.

Any workaround???

Help!

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

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

发布评论

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

评论(1

不知所踪 2024-10-14 15:15:40

可能的方法之一是,

您可以实现 INotifyPropertyChanged 来通知“AreWorkerBusy”更改,在控件中创建依赖属性并将“AreWorkerBusy”与其绑定。

创建两个路由事件,一个用于启动动画,另一个用于停止动画。

在 DP 的属性更改处理程序中,引发特定的路由事件。

在您的控件中编写事件触发器,并根据事件开始或停止动画。

我写过类似的经历, http:// keepitsimpleengineer.blogspot.com/2010/09/wpf-circular-progress-control-part-2.html

One of the possible ways,

You can implement INotifyPropertyChanged to notify 'AreWorkerBusy' changes, create a dependency property in the control and bind 'AreWorkerBusy' with it.

Create two routed events one to start animation and another to stop animation.

In the property changed handler for your DP, raise the specific routed event.

In your control write event triggers, and based on the event start of stop the animation.

I had written a similar experience, http://keepitsimpleengineer.blogspot.com/2010/09/wpf-circular-progress-control-part-2.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文