【问题标题】:WPF Image animationWPF 图像动画
【发布时间】:2013-05-26 11:08:18
【问题描述】:

我有多线程 WPF 应用程序。我的应用程序中有一个在后台运行的小进程,一旦完成,UI 将更新结果。

我已经实现了功能,并且运行良好。我只想为我的应用程序创建如下所示的动画处理图像,以便它会一直运行直到 UI 更新。我不太擅长使用 Expression blend 来创建这种动画。

http://www.google.com/imgres?imgurl=https://www.sunvalleywellness.org/img/animation_processing.gif&imgrefurl=http://www.sunvalleywellness.org/&h=200&w=200&sz=55&tbnid=d4OPzhVnCB_kNM:&tbnh=90&tbnw=90&zoom=1&usg=__KPnWRjNlWm-AuZg0lavRE5lzMcA=&docid=JZavNcJukA3ZwM&sa=X&ei=SlenUcG-DIjtqwGMqYHAAQ&ved=0CDMQ9QEwAg&dur=733

您能帮我创建它吗?我

谢谢

【问题讨论】:

    标签: wpf image animation


    【解决方案1】:

    您必须在 View Model 或 DataContext 中使用 bool 属性。此属性应指示是否在后台工作,例如:IsWorking。当您开始作业时将此属性设置为 true,当您完成作业时,将其设置为 false。请参阅此 DataContext 类的示例代码:

    var currentSyncContext = SynchronizationContext.Current;
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (_,__) =>
                          {
                              currentSyncContext.Send((t)=>{IsWorking = true;},null);     //this is for change the visual tree from another thread
                              //Here write the job you want to do...
                              currentSyncContext.Send((t)=>{IsWorking = false;},null);    //this is for change the visual tree from another thread
                          };
    backgroundWorker.RunWorkerAsync();
    

    然后在您的 XAML 代码中,您需要使用 BooleanToVisibilityConverter 将图像或控件的可见性绑定到此属性。

    我认为这是执行此操作的经典方法。希望对你有用...

    【讨论】:

    • 我明白这一点。我已经实现了。我需要 UI 的图像处理控件。我如何制作带有动画的图像
    • 您可以使用 RotateTransform 为 Image 控件(内部包含您想要的图像)设置动画,并使其永远重复(它是布尔值或枚举值)。然后随时隐藏或显示该控件。
    猜你喜欢
    • 1970-01-01
    • 2016-05-24
    • 2015-05-30
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-02
    相关资源
    最近更新 更多